[ 'renderType' => 'selectIcons', 'disabled' => true, ], 'localizationStateSelector' => [ 'renderType' => 'localizationStateSelector', 'after' => [ 'selectIcons', ], ], 'otherLanguageContent' => [ 'renderType' => 'otherLanguageContent', 'after' => [ 'localizationStateSelector' ], ], 'defaultLanguageDifferences' => [ 'renderType' => 'defaultLanguageDifferences', 'after' => [ 'otherLanguageContent' ], ], ]; public function __construct( private readonly InlineStackProcessor $inlineStackProcessor, ) {} /** * Render single element * * @return array As defined in initializeResultArray() of AbstractNode */ public function render(): array { $resultArray = $this->initializeResultArray(); $table = $this->data['tableName']; $field = $this->data['fieldName']; $parameterArray = $this->data['parameterArray']; $config = $parameterArray['fieldConf']['config']; $selectItems = $parameterArray['fieldConf']['config']['items']; $classList = ['form-select', 'form-control-adapt']; // Check against inline uniqueness $uniqueIds = []; if (($this->data['isInlineChild'] ?? false) && ($this->data['inlineParentUid'] ?? false)) { // If config[foreign_unique] is set for the parent inline field, all // already used unique ids must be excluded from the select items. $inlineObjectName = $this->inlineStackProcessor->getDomObjectIdPrefixFromStructure($this->data['inlineStructure'], $this->data['inlineFirstPid']); if (($this->data['inlineParentConfig']['foreign_table'] ?? false) === $table && ($this->data['inlineParentConfig']['foreign_unique'] ?? false) === $field ) { $classList[] = 't3js-inline-unique'; $uniqueIds = $this->data['inlineData']['unique'][$inlineObjectName . '-' . $table]['used'] ?? []; } // hide uid of parent record for symmetric relations if (($this->data['inlineParentConfig']['foreign_table'] ?? false) === $table && ( ($this->data['inlineParentConfig']['foreign_field'] ?? false) === $field || ($this->data['inlineParentConfig']['symmetric_field'] ?? false) === $field ) ) { $uniqueIds[] = $this->data['inlineParentUid']; } $uniqueIds = array_map(intval(...), $uniqueIds); } // Initialization: $selectId = StringUtility::getUniqueId('tceforms-select-'); $selectedItem = null; $size = (int)($config['size'] ?? 0); // Style set on $options = ''; $disabled = false; if (!empty($config['readOnly'])) { $disabled = true; } // Prepare groups $selectItemCounter = 0; $selectItemGroupCount = 0; $selectItemGroups = []; $selectedValue = ''; $hasIcons = false; // In case e.g. "l10n_display" is set to "defaultAsReadonly" only one value (as string) could be handed in if (!empty($parameterArray['itemFormElValue'])) { if (is_array($parameterArray['itemFormElValue'])) { $selectedValue = (string)$parameterArray['itemFormElValue'][0]; } else { $selectedValue = (string)$parameterArray['itemFormElValue']; } } foreach ($selectItems as $item) { $selected = $selectedValue === (string)$item['value']; if ($item['value'] === '--div--') { // IS OPTGROUP if ($selectItemCounter !== 0) { $selectItemGroupCount++; } $selectItemGroups[$selectItemGroupCount]['header'] = [ 'title' => $item['label'], ]; } elseif ($selected || !in_array((int)$item['value'], $uniqueIds, true)) { $icon = !empty($item['icon']) ? FormEngineUtility::getIconHtml($item['icon'], $item['label'], $item['label']) : ''; $enhancedItem = [ 'title' => $this->appendValueToLabelInDebugMode($item['label'], $item['value']), 'value' => $item['value'], 'icon' => $icon, 'selected' => $selected, ]; if ($selected) { $selectedItem = $enhancedItem; } $selectItemGroups[$selectItemGroupCount]['items'][] = $enhancedItem; $selectItemCounter++; } } // Process groups foreach ($selectItemGroups as $selectItemGroup) { // suppress groups without items if (empty($selectItemGroup['items'])) { continue; } $optionGroup = is_array($selectItemGroup['header'] ?? null); $options .= ($optionGroup ? '' : ''); } // No item selected. Use first item of first group as selected item, which is display // in the form to render icon of that item icon as selected icon when item has one. if ($hasIcons && $selectedItem === null && isset($selectItemGroups[0]['items'][0]) ) { $selectedItem = $selectItemGroups[0]['items'][0]; } $selectAttributes = [ 'id' => $selectId, 'name' => (string)($parameterArray['itemFormElName'] ?? ''), 'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config), 'class' => implode(' ', $classList), ]; if ($size) { $selectAttributes['size'] = (string)$size; } if ($disabled) { $selectAttributes['disabled'] = 'disabled'; } $fieldInformationResult = $this->renderFieldInformation(); $fieldInformationHtml = $fieldInformationResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); $fieldControlResult = $this->renderFieldControl(); $fieldControlHtml = $fieldControlResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false); $fieldWizardResult = $this->renderFieldWizard(); $fieldWizardHtml = $fieldWizardResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); $html = []; $html[] = $this->renderLabel($selectId); $html[] = '