‪TYPO3CMS  ‪main
SelectTreeElement.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\OnFieldChangeInterface;
21 
28 {
34  protected ‪$defaultFieldInformation = [
35  'tcaDescription' => [
36  'renderType' => 'tcaDescription',
37  ],
38  ];
39 
43  protected ‪$defaultFieldWizard = [
44  'localizationStateSelector' => [
45  'renderType' => 'localizationStateSelector',
46  ],
47  ];
48 
55  protected ‪$itemsToShow = 15;
56 
63  protected ‪$minItemsToShow = 5;
64 
70  protected ‪$itemHeight = 20;
71 
78  public function ‪render(): array
79  {
80  $resultArray = $this->‪initializeResultArray();
81  $parameterArray = $this->data['parameterArray'];
82  $formElementId = md5($parameterArray['itemFormElName']);
83 
84  // Field configuration from TCA:
85  $config = $parameterArray['fieldConf']['config'];
86  $readOnly = !empty($config['readOnly']);
87  $exclusiveKeys = !empty($config['exclusiveKeys']) ? $config['exclusiveKeys'] : '';
88  $exclusiveKeys = $exclusiveKeys . ',';
89  $appearance = !empty($config['treeConfig']['appearance']) ? $config['treeConfig']['appearance'] : [];
90  $expanded = !empty($appearance['expandAll']);
91  $showHeader = !empty($appearance['showHeader']);
92  if (isset($config['size']) && (int)$config['size'] > 0) {
93  $height = max($this->minItemsToShow, (int)$config['size']);
94  } else {
95  $height = ‪$this->itemsToShow;
96  }
97  $heightInPx = $height * ‪$this->itemHeight;
98  $treeWrapperId = 'tree_' . $formElementId;
99  $fieldId = 'tree_record_' . $formElementId;
100 
101  $fieldName = $this->data['fieldName'];
102 
103  $dataStructureIdentifier = '';
104  $flexFormSheetName = '';
105  $flexFormFieldName = '';
106  $flexFormContainerName = '';
107  $flexFormContainerIdentifier = '';
108  $flexFormContainerFieldName = '';
109  $flexFormSectionContainerIsNew = false;
110  if ($this->data['processedTca']['columns'][$fieldName]['config']['type'] === 'flex') {
111  $dataStructureIdentifier = $this->data['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier'];
112  if (isset($this->data['flexFormSheetName'])) {
113  $flexFormSheetName = $this->data['flexFormSheetName'];
114  }
115  if (isset($this->data['flexFormFieldName'])) {
116  $flexFormFieldName = $this->data['flexFormFieldName'];
117  }
118  if (isset($this->data['flexFormContainerName'])) {
119  $flexFormContainerName = $this->data['flexFormContainerName'];
120  }
121  if (isset($this->data['flexFormContainerFieldName'])) {
122  $flexFormContainerFieldName = $this->data['flexFormContainerFieldName'];
123  }
124  if (isset($this->data['flexFormContainerIdentifier'])) {
125  $flexFormContainerIdentifier = $this->data['flexFormContainerIdentifier'];
126  }
127  // Add a flag this is a tree in a new flex section container element. This is needed to initialize
128  // the databaseRow with this container again so the tree data provider is able to calculate tree items.
129  if (!empty($this->data['flexSectionContainerPreparation'])) {
130  $flexFormSectionContainerIsNew = true;
131  }
132  }
133 
134  $fieldInformationResult = $this->‪renderFieldInformation();
135  $fieldInformationHtml = $fieldInformationResult['html'];
136  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
137 
138  $fieldWizardResult = $this->‪renderFieldWizard();
139  $fieldWizardHtml = $fieldWizardResult['html'];
140  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
141 
142  $html = [];
143  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
144  $html[] = $fieldInformationHtml;
145  $html[] = '<div class="form-control-wrap">';
146  $html[] = '<div class="form-wizards-wrap">';
147  $html[] = '<div class="form-wizards-element">';
148  $html[] = '<div class="typo3-tceforms-tree">';
149  $html[] = '<input class="treeRecord" type="hidden" id="' . htmlspecialchars($fieldId) . '"';
150  $html[] = ' data-formengine-validation-rules="' . htmlspecialchars($this->‪getValidationDataAsJsonString($config)) . '"';
151  $html[] = ' data-relatedfieldname="' . htmlspecialchars($parameterArray['itemFormElName']) . '"';
152  $html[] = ' data-tablename="' . htmlspecialchars($this->data['tableName']) . '"';
153  $html[] = ' data-fieldname="' . htmlspecialchars($this->data['fieldName']) . '"';
154  $html[] = ' data-uid="' . (int)$this->data['vanillaUid'] . '"';
155  $html[] = ' data-recordtypevalue="' . htmlspecialchars($this->data['recordTypeValue']) . '"';
156  $html[] = ' data-datastructureidentifier="' . htmlspecialchars($dataStructureIdentifier) . '"';
157  $html[] = ' data-flexformsheetname="' . htmlspecialchars($flexFormSheetName) . '"';
158  $html[] = ' data-flexformfieldname="' . htmlspecialchars($flexFormFieldName) . '"';
159  $html[] = ' data-flexformcontainername="' . htmlspecialchars($flexFormContainerName) . '"';
160  $html[] = ' data-flexformcontaineridentifier="' . htmlspecialchars($flexFormContainerIdentifier) . '"';
161  $html[] = ' data-flexformcontainerfieldname="' . htmlspecialchars($flexFormContainerFieldName) . '"';
162  $html[] = ' data-flexformsectioncontainerisnew="' . htmlspecialchars((string)$flexFormSectionContainerIsNew) . '"';
163  $html[] = ' data-command="' . htmlspecialchars($this->data['command']) . '"';
164  $html[] = ' data-read-only="' . ($readOnly ? '1' : '0') . '"';
165  $html[] = ' data-tree-exclusive-keys="' . htmlspecialchars($exclusiveKeys) . '"';
166  $html[] = ' data-tree-expand-up-to-level="' . ($expanded ? '999' : '1') . '"';
167  $html[] = ' data-tree-show-toolbar="' . $showHeader . '"';
168  $html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"';
169  $html[] = ' id="treeinput' . $formElementId . '"';
170  $html[] = ' value="' . htmlspecialchars(implode(',', $parameterArray['itemFormElValue'])) . '"';
171  $html[] = ' data-overridevalues="' . GeneralUtility::jsonEncodeForHtmlAttribute($this->data['overrideValues']) . '"';
172  $html[] = ' data-defaultvalues="' . GeneralUtility::jsonEncodeForHtmlAttribute($this->data['defaultValues']) . '"';
173  $html[] = '/>';
174  $html[] = '</div>';
175  $html[] = '<div id="' . $treeWrapperId . '" class="tree-element" style="height: ' . $heightInPx . 'px;"></div>';
176  $html[] = '</div>';
177  if (!$readOnly && !empty($fieldWizardHtml)) {
178  $html[] = '<div class="form-wizards-items-bottom">';
179  $html[] = $fieldWizardHtml;
180  $html[] = '</div>';
181  }
182  $html[] = '</div>';
183  $html[] = '</div>';
184  $html[] = '</div>';
185 
186  $resultArray['html'] = $this->‪wrapWithFieldsetAndLegend(implode(LF, $html));
187 
188  $onFieldChangeItems = $this->getOnFieldChangeItems($this->‪getFieldChangeFuncs());
189  $resultArray['javaScriptModules']['selectTreeElement'] = ‪JavaScriptModuleInstruction::create(
190  '@typo3/backend/form-engine/element/select-tree-element.js',
191  'SelectTreeElement'
192  )->instance($treeWrapperId, $fieldId, null, $onFieldChangeItems);
193 
194  return $resultArray;
195  }
196 
200  protected function ‪getFieldChangeFuncs(): array
201  {
202  $items = [];
203  $parameterArray = $this->data['parameterArray'];
204  if (!empty($parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'])) {
205  $items[] = $parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
206  }
207  if (!empty($parameterArray['fieldChangeFunc']['alert'])) {
208  $items[] = $parameterArray['fieldChangeFunc']['alert'];
209  }
210  return $items;
211  }
212 }
‪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\SelectTreeElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: SelectTreeElement.php:33
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: SelectTreeElement.php:41
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement\getFieldChangeFuncs
‪list< OnFieldChangeInterface > getFieldChangeFuncs()
Definition: SelectTreeElement.php:195
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:37
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement
Definition: SelectTreeElement.php:28
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\wrapWithFieldsetAndLegend
‪wrapWithFieldsetAndLegend(string $innerHTML)
Definition: AbstractFormElement.php:133
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement\$minItemsToShow
‪int $minItemsToShow
Definition: SelectTreeElement.php:59
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement\render
‪array render()
Definition: SelectTreeElement.php:73
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement\$itemsToShow
‪int $itemsToShow
Definition: SelectTreeElement.php:52
‪TYPO3\CMS\Backend\Form\AbstractNode\getValidationDataAsJsonString
‪getValidationDataAsJsonString(array $config)
Definition: AbstractNode.php:133
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement\$itemHeight
‪int $itemHeight
Definition: SelectTreeElement.php:65
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldWizard
‪array renderFieldWizard()
Definition: AbstractFormElement.php:105
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77