[ 'renderType' => 'localizationStateSelector', ], 'otherLanguageContent' => [ 'renderType' => 'otherLanguageContent', 'after' => [ 'localizationStateSelector', ], ], 'defaultLanguageDifferences' => [ 'renderType' => 'defaultLanguageDifferences', 'after' => [ 'otherLanguageContent', ], ], ]; public function __construct( private readonly IconFactory $iconFactory, ) {} /** * Render check boxes * * @return array As defined in initializeResultArray() of AbstractNode */ public function render(): array { $resultArray = $this->initializeResultArray(); // Field configuration from TCA: $parameterArray = $this->data['parameterArray']; $config = $parameterArray['fieldConf']['config']; $readOnly = (bool)($config['readOnly'] ?? false); $selectItems = $config['items'] ?? []; if (empty($selectItems)) { // Early return in case the field does not contain any items return $resultArray; } // Get item value as array and make unique, which is fine because there can be no duplicates anyway. $itemArray = array_flip($parameterArray['itemFormElValue']); // Initialize variables and traverse the items $groups = []; $currentGroup = 0; $counter = 0; $elementId = StringUtility::getUniqueId('formengine-select-checkbox-'); foreach ($selectItems as $item) { // Non-selectable element: if ($item['value'] === '--div--') { $selIcon = ''; if (isset($item['icon']) && $item['icon'] !== 'empty-empty') { $selIcon = FormEngineUtility::getIconHtml($item['icon']); } $currentGroup++; $groups[$currentGroup]['header'] = [ 'icon' => $selIcon, 'title' => $item['label'], ]; } else { // Check if some help text is available // Help text is expected to be an associative array // with two key, "title" and "description" // For the sake of backwards compatibility, we test if the help text // is a string and use it as a description (this could happen if items // are modified with an itemsProcFunc) $help = ''; if (!empty($item['description'])) { if (is_array($item['description'])) { $helpArray = $item['description']; } else { $helpArray['description'] = $item['description']; } $help = $this->wrapInHelp($helpArray); } // Check if current item is selected. If found, unset the key in the $itemArray. $checked = isset($itemArray[$item['value']]); if ($checked) { unset($itemArray[$item['value']]); } // Build item array $groups[$currentGroup]['items'][] = [ 'id' => $elementId . '-item-' . $counter, 'name' => $parameterArray['itemFormElName'] . '[' . $counter . ']', 'value' => $item['value'], 'checked' => $checked, 'icon' => FormEngineUtility::getIconHtml(!empty($item['icon']) ? $item['icon'] : 'empty-empty'), 'title' => $item['label'], 'help' => $help, ]; $counter++; } } $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[] = '