[ 'renderType' => 'localizationStateSelector', ], ]; /** * Default number of tree nodes to show (determines tree height) * when no ['config']['size'] is set * * @var int */ protected $itemsToShow = 15; /** * Number of items to show at last * e.g. when you have only 2 items in a tree * * @var int */ protected $minItemsToShow = 5; /** * Pixel height of a single tree node * * @var int */ protected $itemHeight = 20; /** * Render tree widget * * @return array As defined in initializeResultArray() of AbstractNode * @see AbstractNode::initializeResultArray() */ public function render(): array { $resultArray = $this->initializeResultArray(); $parameterArray = $this->data['parameterArray']; $formElementId = md5($parameterArray['itemFormElName']); // Field configuration from TCA: $config = $parameterArray['fieldConf']['config']; $readOnly = !empty($config['readOnly']); $exclusiveKeys = !empty($config['exclusiveKeys']) ? $config['exclusiveKeys'] : ''; $exclusiveKeys = $exclusiveKeys . ','; $appearance = !empty($config['treeConfig']['appearance']) ? $config['treeConfig']['appearance'] : []; $expanded = !empty($appearance['expandAll']); $showHeader = !empty($appearance['showHeader']); if (isset($config['size']) && (int)$config['size'] > 0) { $height = max($this->minItemsToShow, (int)$config['size']); } else { $height = $this->itemsToShow; } $heightInPx = $height * $this->itemHeight; $treeWrapperId = 'tree_' . $formElementId; $fieldId = 'tree_record_' . $formElementId; $fieldName = $this->data['fieldName']; $dataStructureIdentifier = ''; $flexFormSheetName = ''; $flexFormFieldName = ''; $flexFormContainerName = ''; $flexFormContainerIdentifier = ''; $flexFormContainerFieldName = ''; $flexFormSectionContainerIsNew = false; if ($this->data['processedTca']['columns'][$fieldName]['config']['type'] === 'flex') { $dataStructureIdentifier = $this->data['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier']; if (isset($this->data['flexFormSheetName'])) { $flexFormSheetName = $this->data['flexFormSheetName']; } if (isset($this->data['flexFormFieldName'])) { $flexFormFieldName = $this->data['flexFormFieldName']; } if (isset($this->data['flexFormContainerName'])) { $flexFormContainerName = $this->data['flexFormContainerName']; } if (isset($this->data['flexFormContainerFieldName'])) { $flexFormContainerFieldName = $this->data['flexFormContainerFieldName']; } if (isset($this->data['flexFormContainerIdentifier'])) { $flexFormContainerIdentifier = $this->data['flexFormContainerIdentifier']; } // Add a flag this is a tree in a new flex section container element. This is needed to initialize // the databaseRow with this container again so the tree data provider is able to calculate tree items. if (!empty($this->data['flexSectionContainerPreparation'])) { $flexFormSectionContainerIsNew = true; } } $fieldInformationResult = $this->renderFieldInformation(); $fieldInformationHtml = $fieldInformationResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); $fieldWizardResult = $this->renderFieldWizard(); $fieldWizardHtml = $fieldWizardResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); $html = []; $html[] = '
'; $html[] = $fieldInformationHtml; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = 'getValidationDataAsJsonString($config)) . '"'; $html[] = ' data-relatedfieldname="' . htmlspecialchars($parameterArray['itemFormElName']) . '"'; $html[] = ' data-tablename="' . htmlspecialchars($this->data['tableName']) . '"'; $html[] = ' data-fieldname="' . htmlspecialchars($this->data['fieldName']) . '"'; $html[] = ' data-uid="' . (int)$this->data['vanillaUid'] . '"'; $html[] = ' data-recordtypevalue="' . htmlspecialchars($this->data['recordTypeValue']) . '"'; $html[] = ' data-datastructureidentifier="' . htmlspecialchars($dataStructureIdentifier) . '"'; $html[] = ' data-flexformsheetname="' . htmlspecialchars($flexFormSheetName) . '"'; $html[] = ' data-flexformfieldname="' . htmlspecialchars($flexFormFieldName) . '"'; $html[] = ' data-flexformcontainername="' . htmlspecialchars($flexFormContainerName) . '"'; $html[] = ' data-flexformcontaineridentifier="' . htmlspecialchars($flexFormContainerIdentifier) . '"'; $html[] = ' data-flexformcontainerfieldname="' . htmlspecialchars($flexFormContainerFieldName) . '"'; $html[] = ' data-flexformsectioncontainerisnew="' . htmlspecialchars((string)$flexFormSectionContainerIsNew) . '"'; $html[] = ' data-command="' . htmlspecialchars($this->data['command']) . '"'; $html[] = ' data-read-only="' . ($readOnly ? '1' : '0') . '"'; $html[] = ' data-tree-exclusive-keys="' . htmlspecialchars($exclusiveKeys) . '"'; $html[] = ' data-tree-expand-up-to-level="' . ($expanded ? '999' : '1') . '"'; $html[] = ' data-tree-show-toolbar="' . $showHeader . '"'; $html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"'; $html[] = ' id="treeinput' . $formElementId . '"'; $html[] = ' value="' . htmlspecialchars(implode(',', $parameterArray['itemFormElValue'])) . '"'; $html[] = ' data-overridevalues="' . GeneralUtility::jsonEncodeForHtmlAttribute($this->data['overrideValues']) . '"'; $html[] = ' data-defaultvalues="' . GeneralUtility::jsonEncodeForHtmlAttribute($this->data['defaultValues']) . '"'; $html[] = '/>'; $html[] = '
'; $html[] = '
'; $html[] = '
'; if (!$readOnly && !empty($fieldWizardHtml)) { $html[] = '
'; $html[] = $fieldWizardHtml; $html[] = '
'; } $html[] = '
'; $html[] = '
'; $html[] = '
'; $resultArray['html'] = $this->wrapWithFieldsetAndLegend(implode(LF, $html)); $onFieldChangeItems = $this->getOnFieldChangeItems($this->getFieldChangeFuncs()); $resultArray['javaScriptModules']['selectTreeElement'] = JavaScriptModuleInstruction::create( '@typo3/backend/form-engine/element/select-tree-element.js', 'SelectTreeElement' )->instance($treeWrapperId, $fieldId, null, $onFieldChangeItems); return $resultArray; } /** * @return list */ protected function getFieldChangeFuncs(): array { $items = []; $parameterArray = $this->data['parameterArray']; if (!empty($parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'])) { $items[] = $parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged']; } if (!empty($parameterArray['fieldChangeFunc']['alert'])) { $items[] = $parameterArray['fieldChangeFunc']['alert']; } return $items; } }