2 namespace TYPO3\CMS\Backend\Form\Element
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Imaging\Icon
;
19 use TYPO3\CMS\Core\Utility\GeneralUtility
;
20 use TYPO3\CMS\Core\Utility\MathUtility
;
21 use TYPO3\CMS\Core\Utility\StringUtility
;
24 * Generation of TCEform elements of the type "input type=text"
26 class InputTextElement
extends AbstractFormElement
29 * This will render a single-line input form field, possibly with various control/validation features
31 * @return array As defined in initializeResultArray() of AbstractNode
33 public function render()
35 $table = $this->data
['tableName'];
36 $fieldName = $this->data
['fieldName'];
37 $row = $this->data
['databaseRow'];
38 $parameterArray = $this->data
['parameterArray'];
39 $resultArray = $this->initializeResultArray();
42 $config = $parameterArray['fieldConf']['config'];
43 $specConf = BackendUtility
::getSpecConfParts($parameterArray['fieldConf']['defaultExtras']);
44 $size = MathUtility
::forceIntegerInRange($config['size'] ?
: $this->defaultInputWidth
, $this->minimumInputWidth
, $this->maxInputWidth
);
45 $evalList = GeneralUtility
::trimExplode(',', $config['eval'], true);
47 $attributes = array();
50 if ($config['readOnly']) {
51 $itemFormElValue = $parameterArray['itemFormElValue'];
52 if (in_array('date', $evalList)) {
53 $config['format'] = 'date';
54 } elseif (in_array('datetime', $evalList)) {
55 $config['format'] = 'datetime';
56 } elseif (in_array('time', $evalList)) {
57 $config['format'] = 'time';
59 if (in_array('password', $evalList)) {
60 $itemFormElValue = $itemFormElValue ?
'*********' : '';
62 $options = $this->data
;
63 $options['parameterArray'] = array(
67 'itemFormElValue' => $itemFormElValue,
69 $options['renderType'] = 'none';
70 return $this->nodeFactory
->create($options)->render();
73 if (in_array('datetime', $evalList, true)
74 ||
in_array('date', $evalList)) {
75 $classes[] = 't3js-datetimepicker';
77 if (in_array('datetime', $evalList)) {
78 $attributes['data-date-type'] = 'datetime';
79 } elseif (in_array('date', $evalList)) {
80 $attributes['data-date-type'] = 'date';
82 if ($parameterArray['itemFormElValue'] > 0) {
83 $parameterArray['itemFormElValue'] +
= date('Z', $parameterArray['itemFormElValue']);
85 if (isset($config['range']['lower'])) {
86 $attributes['data-date-minDate'] = (int)$config['range']['lower'];
88 if (isset($config['range']['upper'])) {
89 $attributes['data-date-maxDate'] = (int)$config['range']['upper'];
91 } elseif (in_array('time', $evalList)) {
93 $classes[] = 't3js-datetimepicker';
94 $attributes['data-date-type'] = 'time';
95 } elseif (in_array('timesec', $evalList)) {
97 $classes[] = 't3js-datetimepicker';
98 $attributes['data-date-type'] = 'timesec';
101 // @todo: The whole eval handling is a mess and needs refactoring
102 foreach ($evalList as $func) {
105 $attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString(array('required' => true));
108 // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
109 // @todo: keyword like "date", or a class reference. The global registration could be dropped then
110 // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
111 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
112 if (class_exists($func)) {
113 $evalObj = GeneralUtility
::makeInstance($func);
114 if (method_exists($evalObj, 'deevaluateFieldValue')) {
116 'value' => $parameterArray['itemFormElValue']
118 $parameterArray['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
125 'field' => $parameterArray['itemFormElName'],
126 'evalList' => implode(',', $evalList),
127 'is_in' => trim($config['is_in']),
130 $classes[] = 'form-control';
131 $classes[] = 't3js-clearable';
132 $classes[] = 'hasDefaultValue';
134 // calculate attributes
135 $attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString($config);
136 $attributes['data-formengine-input-params'] = json_encode($paramsList);
137 $attributes['data-formengine-input-name'] = htmlspecialchars($parameterArray['itemFormElName']);
138 $attributes['id'] = StringUtility
::getUniqueId('formengine-input-');
139 $attributes['value'] = '';
140 if (isset($config['max']) && (int)$config['max'] > 0) {
141 $attributes['maxlength'] = (int)$config['max'];
143 if (!empty($classes)) {
144 $attributes['class'] = implode(' ', $classes);
147 // This is the EDITABLE form field.
148 if (!empty($config['placeholder'])) {
149 $attributes['placeholder'] = trim($config['placeholder']);
152 if (isset($config['autocomplete'])) {
153 $attributes['autocomplete'] = empty($config['autocomplete']) ?
'off' : 'on';
156 // Build the attribute string
157 $attributeString = '';
158 foreach ($attributes as $attributeName => $attributeValue) {
159 $attributeString .= ' ' . $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
165 . $parameterArray['onFocus'] . ' />';
167 // This is the ACTUAL form field - values from the EDITABLE field must be transferred to this field which is the one that is written to the database.
168 $html .= '<input type="hidden" name="' . $parameterArray['itemFormElName'] . '" value="' . htmlspecialchars($parameterArray['itemFormElValue']) . '" />';
170 // Going through all custom evaluations configured for this field
171 // @todo: Similar to above code!
172 foreach ($evalList as $evalData) {
173 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData])) {
174 if (class_exists($evalData)) {
175 $evalObj = GeneralUtility
::makeInstance($evalData);
176 if (method_exists($evalObj, 'returnFieldJS')) {
177 $resultArray['extJSCODE'] .= LF
. 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility
::quoteJSvalue($evalData) . '] = function(value) {' . $evalObj->returnFieldJS() . '}';
186 <div class="input-group">
188 <span class="input-group-btn">
189 <label class="btn btn-default" for="' . $attributes['id'] . '">
190 ' . $this->iconFactory
->getIcon('actions-edit-pick-date', Icon
::SIZE_SMALL
)->render() . '
196 // Wrap a wizard around the item?
197 $html = $this->renderWizards(
204 $parameterArray['itemFormElName'],
208 // Add a wrapper to remain maximum width
209 $width = (int)$this->formMaxWidth($size);
210 $html = '<div class="form-control-wrap"' . ($width ?
' style="max-width: ' . $width . 'px"' : '') . '>' . $html . '</div>';
211 $resultArray['html'] = $html;