‪TYPO3CMS  11.5
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 
18 use TYPO3\CMS\Backend\Form\Behavior\OnFieldChangeTrait;
20 
25 {
26  use OnFieldChangeTrait;
27 
33  protected ‪$defaultFieldInformation = [
34  'tcaDescription' => [
35  'renderType' => 'tcaDescription',
36  ],
37  ];
38 
44  protected ‪$defaultFieldWizard = [
45  'localizationStateSelector' => [
46  'renderType' => 'localizationStateSelector',
47  ],
48  'otherLanguageContent' => [
49  'renderType' => 'otherLanguageContent',
50  'after' => [
51  'localizationStateSelector',
52  ],
53  ],
54  'defaultLanguageDifferences' => [
55  'renderType' => 'defaultLanguageDifferences',
56  'after' => [
57  'otherLanguageContent',
58  ],
59  ],
60  ];
61 
67  public function ‪render()
68  {
69  $resultArray = $this->‪initializeResultArray();
70 
71  $disabled = '';
72  if ($this->data['parameterArray']['fieldConf']['config']['readOnly'] ?? false) {
73  $disabled = ' disabled';
74  }
75 
76  $fieldInformationResult = $this->‪renderFieldInformation();
77  $fieldInformationHtml = $fieldInformationResult['html'];
78  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
79 
80  $fieldWizardResult = $this->‪renderFieldWizard();
81  $fieldWizardHtml = $fieldWizardResult['html'];
82  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
83 
84  $html = [];
85  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
86  $html[] = $fieldInformationHtml;
87  $html[] = '<div class="form-wizards-wrap">';
88  $html[] = '<div class="form-wizards-element">';
89  foreach ($this->data['parameterArray']['fieldConf']['config']['items'] as $itemNumber => $itemLabelAndValue) {
90  $label = $itemLabelAndValue[0];
91  $value = $itemLabelAndValue[1];
92  $radioId = htmlspecialchars($this->data['parameterArray']['itemFormElID'] . '_' . $itemNumber);
93  $radioElementAttrs = array_merge(
94  [
95  'type' => 'radio',
96  'id' => $radioId,
97  'value' => $value,
98  'name' => $this->data['parameterArray']['itemFormElName'],
99  ],
100  $this->getOnFieldChangeAttrs('click', $this->data['parameterArray']['fieldChangeFunc'] ?? [])
101  );
102  if ((string)$value === (string)$this->data['parameterArray']['itemFormElValue']) {
103  $radioElementAttrs['checked'] = 'checked';
104  }
105  $html[] = '<div class="radio' . $disabled . '">';
106  $html[] = '<label for="' . $radioId . '">';
107  $html[] = '<input ' . GeneralUtility::implodeAttributes($radioElementAttrs, true) . $disabled . '>';
108  $html[] = htmlspecialchars($this->‪appendValueToLabelInDebugMode($label, $value));
109  $html[] = '</label>';
110  $html[] = '</div>';
111  }
112  $html[] = '</div>';
113  if (!$disabled && !empty($fieldWizardHtml)) {
114  $html[] = '<div class="form-wizards-items-bottom">';
115  $html[] = $fieldWizardHtml;
116  $html[] = '</div>';
117  }
118  $html[] = '</div>';
119  $html[] = '</div>';
120 
121  $resultArray['html'] = implode(LF, $html);
122  return $resultArray;
123  }
124 }
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:76
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:120
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Backend\Form\Element\RadioElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: RadioElement.php:31
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:35
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Backend\Form\Element\RadioElement\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: RadioElement.php:41
‪TYPO3\CMS\Backend\Form\Element\RadioElement\render
‪array render()
Definition: RadioElement.php:64
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\appendValueToLabelInDebugMode
‪string appendValueToLabelInDebugMode($label, $value)
Definition: AbstractFormElement.php:436
‪TYPO3\CMS\Backend\Form\Element\RadioElement
Definition: RadioElement.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldWizard
‪array renderFieldWizard()
Definition: AbstractFormElement.php:108