[ 'renderType' => 'tcaDescription', ], ]; /** * Default field wizards enabled for this element. * * @var array */ protected $defaultFieldWizard = [ 'localizationStateSelector' => [ 'renderType' => 'localizationStateSelector', ], 'otherLanguageContent' => [ 'renderType' => 'otherLanguageContent', 'after' => [ 'localizationStateSelector' ], ], 'defaultLanguageDifferences' => [ 'renderType' => 'defaultLanguageDifferences', 'after' => [ 'otherLanguageContent', ], ], ]; /** * This will render a single-line input form field, possibly with various control/validation features * * @return array As defined in initializeResultArray() of AbstractNode */ public function render() { $evalData = ''; $languageService = $this->getLanguageService(); $table = $this->data['tableName']; $fieldName = $this->data['fieldName']; $row = $this->data['databaseRow']; $parameterArray = $this->data['parameterArray']; $resultArray = $this->initializeResultArray(); $itemValue = $parameterArray['itemFormElValue']; $config = $parameterArray['fieldConf']['config']; $size = MathUtility::forceIntegerInRange($config['size'] ?: $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth); $evalList = GeneralUtility::trimExplode(',', $config['eval'], true); $width = (int)$this->formMaxWidth($size); $nullControlNameEscaped = htmlspecialchars('control[active][' . $table . '][' . $row['uid'] . '][' . $fieldName . ']'); $fieldInformationResult = $this->renderFieldInformation(); $fieldInformationHtml = $fieldInformationResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); if ($config['readOnly']) { $html = []; $html[] = '
'; $html[] = $fieldInformationHtml; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = ''; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = '
'; $resultArray['html'] = implode(LF, $html); return $resultArray; } // @todo: The whole eval handling is a mess and needs refactoring foreach ($evalList as $func) { // @todo: This is ugly: The code should find out on it's own whether an eval definition is a // @todo: keyword like "date", or a class reference. The global registration could be dropped then // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval() if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) { if (class_exists($func)) { $evalObj = GeneralUtility::makeInstance($func); if (method_exists($evalObj, 'deevaluateFieldValue')) { $_params = [ 'value' => $itemValue ]; $itemValue = $evalObj->deevaluateFieldValue($_params); } if (method_exists($evalObj, 'returnFieldJS')) { // @todo: variable $evalData must be replaced with $func $resultArray['additionalJavaScriptPost'][] = 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($evalData) . '] = function(value) {' . $evalObj->returnFieldJS() . '};'; } } } } // Load needed js library $resultArray['requireJsModules'][] = [ 'TYPO3/CMS/Backend/ColorPicker' => 'function(ColorPicker){ColorPicker.initialize()}' ]; $attributes = [ 'value' => $itemValue, 'id' => StringUtility::getUniqueId('formengine-input-'), 'class' => implode(' ', [ 'form-control', 'hasDefaultValue', 't3js-clearable', 't3js-color-picker', 'formengine-colorpickerelement', ]), 'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config), 'data-formengine-input-params' => (string)json_encode([ 'field' => $parameterArray['itemFormElName'], 'evalList' => implode(',', $evalList), 'is_in' => trim($config['is_in']), ]), 'data-formengine-input-name' => $parameterArray['itemFormElName'], ]; if (isset($config['max']) && (int)$config['max'] > 0) { $attributes['maxlength'] = (string)(int)$config['max']; } if (!empty($config['placeholder'])) { $attributes['placeholder'] = trim($config['placeholder']); } if (isset($config['autocomplete'])) { $attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on'; } $valuePickerHtml = []; if (isset($config['valuePicker']['items']) && is_array($config['valuePicker']['items'])) { $valuePickerHtml[] = ''; } $fieldWizardResult = $this->renderFieldWizard(); $fieldWizardHtml = $fieldWizardResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); $fieldControlResult = $this->renderFieldControl(); $fieldControlHtml = $fieldControlResult['html']; $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false); $mainFieldHtml = []; $mainFieldHtml[] = '
'; $mainFieldHtml[] = '
'; $mainFieldHtml[] = '
'; $mainFieldHtml[] = ''; $mainFieldHtml[] = ''; $mainFieldHtml[] = '
'; $mainFieldHtml[] = '
'; $mainFieldHtml[] = '
'; $mainFieldHtml[] = $fieldControlHtml; $mainFieldHtml[] = implode(LF, $valuePickerHtml); $mainFieldHtml[] = '
'; $mainFieldHtml[] = '
'; if (!empty($fieldWizardHtml)) { $mainFieldHtml[] = '
'; $mainFieldHtml[] = $fieldWizardHtml; $mainFieldHtml[] = '
'; } $mainFieldHtml[] = '
'; $mainFieldHtml[] = '
'; $mainFieldHtml = implode(LF, $mainFieldHtml); $fullElement = $mainFieldHtml; if ($this->hasNullCheckboxButNoPlaceholder()) { $checked = $itemValue !== null ? ' checked="checked"' : ''; $fullElement = []; $fullElement[] = '
'; $fullElement[] = '
'; $fullElement[] = ''; $fullElement[] = '
'; $fullElement[] = $mainFieldHtml; $fullElement = implode(LF, $fullElement); } elseif ($this->hasNullCheckboxWithPlaceholder()) { $checked = $itemValue !== null ? ' checked="checked"' : ''; $placeholder = $shortenedPlaceholder = $config['placeholder'] ?? ''; $disabled = ''; $fallbackValue = 0; if (strlen($placeholder) > 0) { $shortenedPlaceholder = GeneralUtility::fixed_lgd_cs($placeholder, 20); if ($placeholder !== $shortenedPlaceholder) { $overrideLabel = sprintf( $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'), '' . htmlspecialchars($shortenedPlaceholder) . '' ); } else { $overrideLabel = sprintf( $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'), htmlspecialchars($placeholder) ); } } else { $overrideLabel = $languageService->sL( 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override_not_available' ); } $fullElement = []; $fullElement[] = '
'; $fullElement[] = ''; $fullElement[] = '
'; $fullElement[] = '
'; $fullElement[] = '
'; $fullElement[] = ''; $fullElement[] = '
'; $fullElement[] = '
'; $fullElement[] = '
'; $fullElement[] = $mainFieldHtml; $fullElement[] = '
'; $fullElement = implode(LF, $fullElement); } $resultArray['html'] = '
' . $fieldInformationHtml . $fullElement . '
'; return $resultArray; } /** * @return LanguageService */ protected function getLanguageService() { return $GLOBALS['LANG']; } }