[ 'renderType' => 'localizationStateSelector', ], 'otherLanguageContent' => [ 'renderType' => 'otherLanguageContent', 'after' => [ 'localizationStateSelector', ], ], 'defaultLanguageDifferences' => [ 'renderType' => 'defaultLanguageDifferences', 'after' => [ 'otherLanguageContent', ], ], ]; /** * This will render a checkbox or an array of checkboxes * * @return array As defined in initializeResultArray() of AbstractNode */ public function render(): array { $resultArray = $this->initializeResultArray(); $elementHtml = ''; $disabled = false; if ($this->data['parameterArray']['fieldConf']['config']['readOnly'] ?? false) { $disabled = true; } // Traversing the array of items $items = $this->data['parameterArray']['fieldConf']['config']['items'] ?? []; $numberOfItems = count($items); if ($numberOfItems === 0) { $items[] = ['label' => '']; $numberOfItems = 1; } // The values in the array may be numeric strings, but we need real ints. $formElementValue = (int)($this->data['parameterArray']['itemFormElValue'] ?? 0); $cols = (int)($this->data['parameterArray']['fieldConf']['config']['cols'] ?? 0); if ($cols > 1) { $elementHtml .= '
'; // $itemKey is important here, because items could have been removed via TSConfig foreach ($items as $itemKey => $itemDefinition) { $label = $itemDefinition['label']; $elementHtml .= '
' . $this->renderSingleCheckboxElement($label, $itemKey, $formElementValue, $numberOfItems, $this->data['parameterArray'], $disabled) . '
'; } $elementHtml .= '
'; } else { $counter = 0; foreach ($items as $itemDefinition) { $label = $itemDefinition['label']; $elementHtml .= $this->renderSingleCheckboxElement($label, $counter, $formElementValue, $numberOfItems, $this->data['parameterArray'], $disabled); ++$counter; } } if (!$disabled) { $elementHtml .= ''; } $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[] = $elementHtml; $html[] = '
'; if (!$disabled && !empty($fieldWizardHtml)) { $html[] = '
'; $html[] = $fieldWizardHtml; $html[] = '
'; } $html[] = '
'; $html[] = '
'; $resultArray['html'] = $this->wrapWithFieldsetAndLegend(implode(LF, $html)); return $resultArray; } /** * This functions builds the HTML output for the checkbox * * @param string $label Label of this item * @param int $itemCounter Number of this element in the list of all elements * @param int $formElementValue Value of this element * @param int $numberOfItems Full number of items * @param array $additionalInformation Information with additional configuration options * @param bool $disabled TRUE if form element is disabled * @return string Single element HTML */ protected function renderSingleCheckboxElement($label, $itemCounter, $formElementValue, $numberOfItems, $additionalInformation, $disabled): string { $languageService = $this->getLanguageService(); $parentLabel = $additionalInformation['fieldConf']['label'] ?? ''; $config = $additionalInformation['fieldConf']['config']; $inline = ($config['cols'] ?? '') === 'inline'; $invert = isset($config['items'][0]['invertStateDisplay']) && $config['items'][0]['invertStateDisplay'] === true; $checkboxParameters = $this->checkBoxParams( $additionalInformation['itemFormElName'], $formElementValue, $itemCounter, $numberOfItems, $additionalInformation['fieldChangeFunc'] ?? [], $invert ); $checkboxId = htmlspecialchars(StringUtility::getUniqueId('formengine-check-toggle-') . '-' . $itemCounter); return '
'; } }