‪TYPO3CMS  ‪main
RadioElement.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
31  protected ‪$defaultFieldInformation = [
32  'tcaDescription' => [
33  'renderType' => 'tcaDescription',
34  ],
35  ];
36 
42  protected ‪$defaultFieldWizard = [
43  'localizationStateSelector' => [
44  'renderType' => 'localizationStateSelector',
45  ],
46  'otherLanguageContent' => [
47  'renderType' => 'otherLanguageContent',
48  'after' => [
49  'localizationStateSelector',
50  ],
51  ],
52  'defaultLanguageDifferences' => [
53  'renderType' => 'defaultLanguageDifferences',
54  'after' => [
55  'otherLanguageContent',
56  ],
57  ],
58  ];
59 
65  public function ‪render(): array
66  {
67  $resultArray = $this->‪initializeResultArray();
68 
69  $disabled = '';
70  if ($this->data['parameterArray']['fieldConf']['config']['readOnly'] ?? false) {
71  $disabled = ' disabled';
72  }
73 
74  $fieldInformationResult = $this->‪renderFieldInformation();
75  $fieldInformationHtml = $fieldInformationResult['html'];
76  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
77 
78  $fieldWizardResult = $this->‪renderFieldWizard();
79  $fieldWizardHtml = $fieldWizardResult['html'];
80  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
81 
82  $html = [];
83  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
84  $html[] = $fieldInformationHtml;
85  $html[] = '<div class="form-wizards-wrap">';
86  $html[] = '<div class="form-wizards-element">';
87  foreach ($this->data['parameterArray']['fieldConf']['config']['items'] as $itemNumber => $itemLabelAndValue) {
88  $label = $itemLabelAndValue['label'];
89  $value = $itemLabelAndValue['value'];
90  $radioId = htmlspecialchars(‪StringUtility::getUniqueId('formengine-radio-') . '-' . $itemNumber);
91  $radioElementAttrs = array_merge(
92  [
93  'type' => 'radio',
94  'id' => $radioId,
95  'value' => $value,
96  'class' => 'form-check-input',
97  'name' => $this->data['parameterArray']['itemFormElName'],
98  ],
99  $this->getOnFieldChangeAttrs('click', $this->data['parameterArray']['fieldChangeFunc'] ?? [])
100  );
101  if ((string)$value === (string)$this->data['parameterArray']['itemFormElValue']) {
102  $radioElementAttrs['checked'] = 'checked';
103  }
104  $html[] = '<div class="form-check' . $disabled . '">';
105  $html[] = '<input ' . GeneralUtility::implodeAttributes($radioElementAttrs, true, true) . $disabled . '>';
106  $html[] = '<label class="form-check-label" for="' . $radioId . '">';
107  $html[] = htmlspecialchars($this->‪appendValueToLabelInDebugMode($label, $value));
108  $html[] = '</label>';
109  $html[] = '</div>';
110  }
111  $html[] = '</div>';
112  if (!$disabled && !empty($fieldWizardHtml)) {
113  $html[] = '<div class="form-wizards-items-bottom">';
114  $html[] = $fieldWizardHtml;
115  $html[] = '</div>';
116  }
117  $html[] = '</div>';
118  $html[] = '</div>';
119 
120  $resultArray['html'] = $this->‪wrapWithFieldsetAndLegend(implode(LF, $html));
121  return $resultArray;
122  }
123 }
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:73
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Backend\Form\Element\RadioElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: RadioElement.php:30
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:37
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\wrapWithFieldsetAndLegend
‪wrapWithFieldsetAndLegend(string $innerHTML)
Definition: AbstractFormElement.php:133
‪TYPO3\CMS\Backend\Form\Element\RadioElement\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: RadioElement.php:40
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\appendValueToLabelInDebugMode
‪appendValueToLabelInDebugMode(string|int $label, string|int $value)
Definition: AbstractFormElement.php:447
‪TYPO3\CMS\Backend\Form\Element\RadioElement\render
‪array render()
Definition: RadioElement.php:63
‪TYPO3\CMS\Backend\Form\Element\RadioElement
Definition: RadioElement.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldWizard
‪array renderFieldWizard()
Definition: AbstractFormElement.php:105
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77