[!!!][FEATURE] FormEngine element level refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Element / NoneElement.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Element;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\MathUtility;
18
19 /**
20 * None element is a "disabled" input element with formatted values if needed.
21 */
22 class NoneElement extends AbstractFormElement
23 {
24 /**
25 * Default field wizards enabled for this element.
26 *
27 * @var array
28 */
29 protected $defaultFieldWizard = [
30 'otherLanguageContent' => [
31 'renderType' => 'otherLanguageContent',
32 ],
33 'defaultLanguageDifferences' => [
34 'renderType' => 'defaultLanguageDifferences',
35 'after' => [
36 'otherLanguageContent',
37 ],
38 ],
39 ];
40
41 /**
42 * This will render a non-editable display of the content of the field.
43 *
44 * @return string The HTML code for the TCEform field
45 */
46 public function render()
47 {
48 $resultArray = $this->initializeResultArray();
49
50 $parameterArray = $this->data['parameterArray'];
51 $config = $parameterArray['fieldConf']['config'];
52 $itemValue = $parameterArray['itemFormElValue'];
53
54 if (isset($config['format']) && $config['format']) {
55 $formatOptions = $config['format.'] ?? [];
56 $itemValue = $this->formatValue($config['format'], $itemValue, $formatOptions);
57 }
58 if (!$config['pass_content']) {
59 $itemValue = htmlspecialchars($itemValue);
60 }
61
62 $cols = $config['cols'] ?: ($config['size'] ?: $this->defaultInputWidth);
63 $size = MathUtility::forceIntegerInRange($cols ?: $this->defaultInputWidth, 5, $this->maxInputWidth);
64 $width = $this->formMaxWidth($size);
65
66 $fieldInformationResult = $this->renderFieldInformation();
67 $fieldInformationHtml = $fieldInformationResult['html'];
68 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
69
70 $html = [];
71 $html[] = '<div class="t3js-formengine-field-item">';
72 $html[] = $fieldInformationHtml;
73 $html[] = '<div class="form-wizards-wrap">';
74 $html[] = '<div class="form-wizards-element">';
75 $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
76 $html[] = '<input class="form-control" value="' . htmlspecialchars($itemValue) . '" type="text" disabled>';
77 $html[] = '</div>';
78 $html[] = '</div>';
79 $html[] = '</div>';
80 $html[] = '</div>';
81
82 $resultArray['html'] = implode(LF, $html);
83
84 return $resultArray;
85 }
86 }