[TASK] Render wizards of FormEngine elements only if needed
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Element / RadioElement.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Element;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Render elements of type radio
19 */
20 class RadioElement extends AbstractFormElement
21 {
22 /**
23 * Default field information enabled for this element.
24 *
25 * @var array
26 */
27 protected $defaultFieldInformation = [
28 'tcaDescription' => [
29 'renderType' => 'tcaDescription',
30 ],
31 ];
32
33 /**
34 * Default field wizards enabled for this element.
35 *
36 * @var array
37 */
38 protected $defaultFieldWizard = [
39 'localizationStateSelector' => [
40 'renderType' => 'localizationStateSelector',
41 ],
42 'otherLanguageContent' => [
43 'renderType' => 'otherLanguageContent',
44 'after' => [
45 'localizationStateSelector'
46 ],
47 ],
48 'defaultLanguageDifferences' => [
49 'renderType' => 'defaultLanguageDifferences',
50 'after' => [
51 'otherLanguageContent',
52 ],
53 ],
54 ];
55
56 /**
57 * This will render a series of radio buttons.
58 *
59 * @return array As defined in initializeResultArray() of AbstractNode
60 */
61 public function render()
62 {
63 $resultArray = $this->initializeResultArray();
64
65 $disabled = '';
66 if ($this->data['parameterArray']['fieldConf']['config']['readOnly']) {
67 $disabled = ' disabled';
68 }
69
70 $fieldInformationResult = $this->renderFieldInformation();
71 $fieldInformationHtml = $fieldInformationResult['html'];
72 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
73
74 $fieldWizardResult = $this->renderFieldWizard();
75 $fieldWizardHtml = $fieldWizardResult['html'];
76 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
77
78 $html = [];
79 $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
80 $html[] = $fieldInformationHtml;
81 $html[] = '<div class="form-wizards-wrap">';
82 $html[] = '<div class="form-wizards-element">';
83
84 foreach ($this->data['parameterArray']['fieldConf']['config']['items'] as $itemNumber => $itemLabelAndValue) {
85 $label = $itemLabelAndValue[0];
86 $value = $itemLabelAndValue[1];
87 $radioId = htmlspecialchars($this->data['parameterArray']['itemFormElID'] . '_' . $itemNumber);
88 $radioChecked = (string)$value === (string)$this->data['parameterArray']['itemFormElValue'] ? ' checked="checked"' : '';
89
90 $html[] = '<div class="radio' . $disabled . '">';
91 $html[] = '<label for="' . $radioId . '">';
92 $html[] = '<input type="radio"';
93 $html[] = ' name="' . htmlspecialchars($this->data['parameterArray']['itemFormElName']) . '"';
94 $html[] = ' id="' . $radioId . '"';
95 $html[] = ' value="' . htmlspecialchars($value) . '"';
96 $html[] = $radioChecked;
97 $html[] = $disabled;
98 $html[] = ' onclick="' . htmlspecialchars(implode('', $this->data['parameterArray']['fieldChangeFunc'])) . '"';
99 $html[] = '/>';
100 $html[] = htmlspecialchars($this->appendValueToLabelInDebugMode($label, $value));
101 $html[] = '</label>';
102 $html[] = '</div>';
103 }
104 if (!$disabled && !empty($fieldWizardHtml)) {
105 $html[] = '<div class="form-wizards-items-bottom">';
106 $html[] = $fieldWizardHtml;
107 $html[] = '</div>';
108 }
109 $html[] = '</div>';
110 $html[] = '</div>';
111
112 $resultArray['html'] = implode(LF, $html);
113 return $resultArray;
114 }
115 }