[TASK] Remove unnecessary help-block in ReadOnly select
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Backend\Form\FormEngine;
21
22 /**
23 * Generation of TCEform elements where no rendering could be found
24 */
25 class NoneElement extends AbstractFormElement {
26
27 /**
28 * This will render a non-editable display of the content of the field.
29 *
30 * @return string The HTML code for the TCEform field
31 */
32 public function render() {
33 $parameterArray = $this->globalOptions['parameterArray'];
34 $config = $parameterArray['fieldConf']['config'];
35 $itemValue = $parameterArray['itemFormElValue'];
36
37 if ($config['format']) {
38 $itemValue = $this->formatValue($config, $itemValue);
39 }
40 if (!$config['pass_content']) {
41 $itemValue = htmlspecialchars($itemValue);
42 }
43
44 $resultArray = $this->initializeResultArray();
45 $rows = (int)$config['rows'];
46 // Render as textarea
47 if ($rows > 1 || $config['type'] === 'text') {
48 if (!$config['pass_content']) {
49 $itemValue = nl2br($itemValue);
50 }
51 $cols = MathUtility::forceIntegerInRange($config['cols'] ?: $this->defaultInputWidth, 5, $this->maxInputWidth);
52 $width = $this->formMaxWidth($cols);
53 $html = '
54 <div class="form-control-wrap"' . ($width ? ' style="max-width: ' . $width . 'px"' : '') . '>
55 <textarea class="form-control" rows="' . $rows . '" disabled>' . $itemValue . '</textarea>
56 </div>';
57 } else {
58 $cols = $config['cols'] ?: ($config['size'] ?: $this->defaultInputWidth);
59 $size = MathUtility::forceIntegerInRange($cols ?: $this->defaultInputWidth, 5, $this->maxInputWidth);
60 $width = $this->formMaxWidth($size);
61 $html = '
62 <div class="form-control-wrap"' . ($width ? ' style="max-width: ' . $width . 'px"' : '') . '>
63 <input class="form-control" value="'. $itemValue .'" type="text" disabled>
64 </div>';
65 }
66 $resultArray['html'] = $html;
67 return $resultArray;
68 }
69
70 /**
71 * Format field content if $config['format'] is set to date, filesize, ..., user
72 *
73 * @param array $config Configuration for the display
74 * @param string $itemValue The value to display
75 * @return string Formatted field value
76 */
77 protected function formatValue($config, $itemValue) {
78 $format = trim($config['format']);
79 switch ($format) {
80 case 'date':
81 if ($itemValue) {
82 $option = trim($config['format.']['option']);
83 if ($option) {
84 if ($config['format.']['strftime']) {
85 $value = strftime($option, $itemValue);
86 } else {
87 $value = date($option, $itemValue);
88 }
89 } else {
90 $value = date('d-m-Y', $itemValue);
91 }
92 } else {
93 $value = '';
94 }
95 if ($config['format.']['appendAge']) {
96 $age = BackendUtility::calcAge(
97 $GLOBALS['EXEC_TIME'] - $itemValue,
98 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')
99 );
100 $value .= ' (' . $age . ')';
101 }
102 $itemValue = $value;
103 break;
104 case 'datetime':
105 // compatibility with "eval" (type "input")
106 if ($itemValue !== '') {
107 $itemValue = date('H:i d-m-Y', (int)$itemValue);
108 }
109 break;
110 case 'time':
111 // compatibility with "eval" (type "input")
112 if ($itemValue !== '') {
113 $itemValue = date('H:i', (int)$itemValue);
114 }
115 break;
116 case 'timesec':
117 // compatibility with "eval" (type "input")
118 if ($itemValue !== '') {
119 $itemValue = date('H:i:s', (int)$itemValue);
120 }
121 break;
122 case 'year':
123 // compatibility with "eval" (type "input")
124 if ($itemValue !== '') {
125 $itemValue = date('Y', (int)$itemValue);
126 }
127 break;
128 case 'int':
129 $baseArr = array('dec' => 'd', 'hex' => 'x', 'HEX' => 'X', 'oct' => 'o', 'bin' => 'b');
130 $base = trim($config['format.']['base']);
131 $format = $baseArr[$base] ?: 'd';
132 $itemValue = sprintf('%' . $format, $itemValue);
133 break;
134 case 'float':
135 $precision = MathUtility::forceIntegerInRange($config['format.']['precision'], 1, 10, 2);
136 $itemValue = sprintf('%.' . $precision . 'f', $itemValue);
137 break;
138 case 'number':
139 $format = trim($config['format.']['option']);
140 $itemValue = sprintf('%' . $format, $itemValue);
141 break;
142 case 'md5':
143 $itemValue = md5($itemValue);
144 break;
145 case 'filesize':
146 // We need to cast to int here, otherwise empty values result in empty output,
147 // but we expect zero.
148 $value = GeneralUtility::formatSize((int)$itemValue);
149 if ($config['format.']['appendByteSize']) {
150 $value .= ' (' . $itemValue . ')';
151 }
152 $itemValue = $value;
153 break;
154 case 'user':
155 $func = trim($config['format.']['userFunc']);
156 if ($func) {
157 $dummyFormEngine = new FormEngine;
158 $params = array(
159 'value' => $itemValue,
160 'args' => $config['format.']['userFunc'],
161 'config' => $config,
162 'pObj' => $dummyFormEngine
163 );
164 $itemValue = GeneralUtility::callUserFunction($func, $params, $dummyFormEngine);
165 }
166 break;
167 default:
168 // Do nothing e.g. when $format === ''
169 }
170 return $itemValue;
171 }
172
173 }