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