[
'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(): array
{
$table = $this->data['tableName'];
$fieldName = $this->data['fieldName'];
$parameterArray = $this->data['parameterArray'];
$resultArray = $this->initializeResultArray();
$config = $parameterArray['fieldConf']['config'];
$format = $config['format'] ?? 'integer';
if ($format !== 'integer' && $format !== 'decimal') {
throw new \UnexpectedValueException(
'Format "' . $format . '" for field "' . $fieldName . '" in table "' . $table . '" is '
. 'not valid. Must be either empty or set to one of: "integer", "decimal".',
1649124682
);
}
// @todo This should be configurable (e.g. [config][precision])
$precision = 2;
$itemValue = $parameterArray['itemFormElValue'];
$width = $this->formMaxWidth(
MathUtility::forceIntegerInRange($config['size'] ?? $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth)
);
$fieldId = StringUtility::getUniqueId('formengine-input-');
$itemName = (string)$parameterArray['itemFormElName'];
$renderedLabel = $this->renderLabel($fieldId);
$fieldInformationResult = $this->renderFieldInformation();
$fieldInformationHtml = $fieldInformationResult['html'];
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
if ($config['readOnly'] ?? false) {
$html = [];
$html[] = $renderedLabel;
$html[] = '
';
$resultArray['html'] = implode(LF, $html);
return $resultArray;
}
$languageService = $this->getLanguageService();
// Always add the format.
$evalList = [$format];
if ($config['nullable'] ?? false) {
$evalList[] = 'null';
}
$attributes = [
'value' => '',
'id' => $fieldId,
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-formengine-input-params' => (string)json_encode([
'field' => $itemName,
'evalList' => implode(',', $evalList),
], JSON_THROW_ON_ERROR),
'data-formengine-input-name' => $itemName,
];
if (!empty($config['placeholder'])) {
$attributes['placeholder'] = trim($config['placeholder']);
}
if (isset($config['autocomplete'])) {
$attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on';
}
$valueSliderHtml = [];
if (is_array($config['slider'] ?? false)) {
if ($format === 'decimal') {
$itemValue = (float)$itemValue;
} else {
$itemValue = (int)$itemValue;
}
$valueSliderConfiguration = [
'precision' => (string)$precision,
'format' => $format,
'linked-field' => '[data-formengine-input-name="' . $itemName . '"]',
];
$rangeAttributes = [
'type' => 'range',
'class' => 'form-range-input',
'min' => (string)(float)($config['range']['lower'] ?? 0),
'max' => (string)(float)($config['range']['upper'] ?? 10000),
'step' => (string)($config['slider']['step'] ?? 1),
'style' => 'width: ' . (int)($config['slider']['width'] ?? 400) . 'px',
'title' => (string)$itemValue,
'value' => (string)$itemValue,
];
$valueSliderHtml[] = '';
$valueSliderHtml[] = '';
$valueSliderHtml[] = '';
$valueSliderHtml[] = '
';
$valueSliderHtml[] = '';
$resultArray['javaScriptModules'][] = JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-wizard/value-slider.js');
}
$fieldControlResult = $this->renderFieldControl();
$fieldControlHtml = $fieldControlResult['html'];
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
$fieldWizardResult = $this->renderFieldWizard();
$fieldWizardHtml = $fieldWizardResult['html'];
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
if (isset($config['range']['lower'])) {
$attributes['min'] = (string)(float)$config['range']['lower'];
}
if (isset($config['range']['upper'])) {
$attributes['max'] = (string)(float)$config['range']['upper'];
}
if ($format === 'decimal') {
$attributes['step'] = '0.' . str_repeat('0', $precision - 1) . '1';
}
$mainFieldHtml = [];
$mainFieldHtml[] = '';
$mainFieldHtml = implode(LF, $mainFieldHtml);
$nullControlNameEscaped = htmlspecialchars('control[active][' . $table . '][' . $this->data['databaseRow']['uid'] . '][' . $fieldName . ']');
$fullElement = $mainFieldHtml;
if ($this->hasNullCheckboxButNoPlaceholder()) {
$checked = $itemValue !== null ? ' checked="checked"' : '';
$fullElement = [];
$fullElement[] = '';
$fullElement[] = '';
$fullElement[] = '';
$fullElement[] = '';
$fullElement[] = '';
$fullElement[] = '
';
$fullElement[] = $mainFieldHtml;
$fullElement = implode(LF, $fullElement);
} elseif ($this->hasNullCheckboxWithPlaceholder()) {
$checked = $itemValue !== null ? ' checked="checked"' : '';
$placeholder = $shortenedPlaceholder = trim((string)($config['placeholder'] ?? ''));
if ($placeholder !== '') {
$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[] = $mainFieldHtml;
$fullElement[] = '
';
$fullElement = implode(LF, $fullElement);
}
$resultArray['html'] = $renderedLabel . '
' . $fieldInformationHtml . $fullElement . '
';
return $resultArray;
}
}