TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
TextElement.php
Go to the documentation of this file.
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 
22 
27 {
34  protected $charactersPerRow = 40;
35 
41  public function render()
42  {
43  $table = $this->data['tableName'];
44  $fieldName = $this->data['fieldName'];
45  $row = $this->data['databaseRow'];
46  $parameterArray = $this->data['parameterArray'];
47  $resultArray = $this->initializeResultArray();
48  $backendUser = $this->getBackendUserAuthentication();
49 
50  $config = $parameterArray['fieldConf']['config'];
51 
52  // Setting columns number
53  $cols = MathUtility::forceIntegerInRange($config['cols'] ?: $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth);
54 
55  // Setting number of rows
56  $rows = MathUtility::forceIntegerInRange($config['rows'] ?: 5, 1, 20);
57  $originalRows = $rows;
58 
59  $itemFormElementValueLength = strlen($parameterArray['itemFormElValue']);
60  if ($itemFormElementValueLength > $this->charactersPerRow * 2) {
61  $cols = $this->maxInputWidth;
63  round($itemFormElementValueLength / $this->charactersPerRow),
64  count(explode(LF, $parameterArray['itemFormElValue'])),
65  20
66  );
67  if ($rows < $originalRows) {
68  $rows = $originalRows;
69  }
70  }
71 
72  // must be called after the cols and rows calculation, so the parameters are applied
73  // to read-only fields as well.
74  // @todo: Same as in InputTextElement ...
75  if ($config['readOnly']) {
76  $config['cols'] = $cols;
77  $config['rows'] = $rows;
78  $options = $this->data;
79  $options['parameterArray'] = [
80  'fieldConf' => [
81  'config' => $config,
82  ],
83  'itemFormElValue' => $parameterArray['itemFormElValue'],
84  ];
85  $options['renderType'] = 'none';
86  return $this->nodeFactory->create($options)->render();
87  }
88 
89  $evalList = GeneralUtility::trimExplode(',', $config['eval'], true);
90  // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
91  $specialConfiguration = BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras']);
92  $html = '';
93 
94  // Show message, if no RTE (field can only be edited with RTE!)
95  if ($specialConfiguration['rte_only']) {
96  $html = '<p><em>' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.noRTEfound')) . '</em></p>';
97  } else {
98  $attributes = [];
99  // validation
100  foreach ($evalList as $func) {
101  if ($func === 'required') {
102  $attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString(['required' => true]);
103  } else {
104  // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
105  // @todo: keyword like "date", or a class reference. The global registration could be dropped then
106  // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
107  // There is a similar hook for "evaluateFieldValue" in DataHandler and InputTextElement
108  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
109  if (class_exists($func)) {
110  $evalObj = GeneralUtility::makeInstance($func);
111  if (method_exists($evalObj, 'deevaluateFieldValue')) {
112  $_params = [
113  'value' => $parameterArray['itemFormElValue']
114  ];
115  $parameterArray['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
116  }
117  }
118  }
119  }
120  }
121 
122  // calculate classes
123  $classes = [];
124  $classes[] = 'form-control';
125  $classes[] = 't3js-formengine-textarea';
126  $classes[] = 'formengine-textarea';
127  if ($specialConfiguration['fixed-font']) {
128  $classes[] = 'text-monospace';
129  }
130  if ($specialConfiguration['enable-tab']) {
131  $classes[] = 't3js-enable-tab';
132  }
133 
134  // calculate styles
135  $styles = [];
136  // add the max-height from the users' preference to it
137  $maximumHeight = (int)$backendUser->uc['resizeTextareas_MaxHeight'];
138  if ($maximumHeight > 0) {
139  $styles[] = 'max-height: ' . $maximumHeight . 'px';
140  }
141 
142  // calculate attributes
143  $attributes['id'] = StringUtility::getUniqueId('formengine-textarea-');
144  $attributes['name'] = htmlspecialchars($parameterArray['itemFormElName']);
145  $attributes['data-formengine-input-name'] = htmlspecialchars($parameterArray['itemFormElName']);
146  if (!empty($styles)) {
147  $attributes['style'] = implode(' ', $styles);
148  }
149  if (!empty($classes)) {
150  $attributes['class'] = implode(' ', $classes);
151  }
152  $attributes['rows'] = $rows;
153  $attributes['wrap'] = $specialConfiguration['nowrap'] ? 'off' : ($config['wrap'] ?: 'virtual');
154  $attributes['onChange'] = implode('', $parameterArray['fieldChangeFunc']);
155  if (isset($config['max']) && (int)$config['max'] > 0) {
156  $attributes['maxlength'] = (int)$config['max'];
157  }
158  $attributeString = '';
159  foreach ($attributes as $attributeName => $attributeValue) {
160  $attributeString .= ' ' . $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
161  }
162 
163  // Build the textarea
164  $placeholderAttribute = '';
165  if (!empty($config['placeholder'])) {
166  $placeholderAttribute = ' placeholder="' . htmlspecialchars(trim($config['placeholder'])) . '" ';
167  }
168 
169  $html .= '<textarea'
170  . $attributeString
171  . $placeholderAttribute
172  . '>' . htmlspecialchars($parameterArray['itemFormElValue']) . '</textarea>';
173 
174  // Wrap a wizard around the item?
175  $html = $this->renderWizards(
176  [$html],
177  $config['wizards'],
178  $table,
179  $row,
180  $fieldName,
181  $parameterArray,
182  $parameterArray['itemFormElName'],
183  $specialConfiguration,
184  false
185  );
186 
187  $maximumWidth = (int)$this->formMaxWidth($cols);
188  $html = '<div class="form-control-wrap"' . ($maximumWidth ? ' style="max-width: ' . $maximumWidth . 'px"' : '') . '>' . $html . '</div>';
189  }
190 
191  $resultArray['html'] = $html;
192  return $resultArray;
193  }
194 
198  protected function getBackendUserAuthentication()
199  {
200  return $GLOBALS['BE_USER'];
201  }
202 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31