TYPO3 CMS  TYPO3_8-7
TextTableElement.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 
21 
26 {
32  protected $defaultFieldWizard = [
33  'localizationStateSelector' => [
34  'renderType' => 'localizationStateSelector',
35  ],
36  'otherLanguageContent' => [
37  'renderType' => 'otherLanguageContent',
38  'after' => [
39  'localizationStateSelector'
40  ],
41  ],
42  'defaultLanguageDifferences' => [
43  'renderType' => 'defaultLanguageDifferences',
44  'after' => [
45  'otherLanguageContent',
46  ],
47  ],
48  ];
49 
55  protected $defaultFieldControl = [
56  'tableWizard' => [
57  'renderType' => 'tableWizard',
58  ],
59  ];
60 
67  protected $charactersPerRow = 40;
68 
74  public function render()
75  {
76  $backendUser = $this->getBackendUserAuthentication();
77 
78  $parameterArray = $this->data['parameterArray'];
79  $resultArray = $this->initializeResultArray();
80 
81  $itemValue = $parameterArray['itemFormElValue'];
82  $config = $parameterArray['fieldConf']['config'];
83  $evalList = GeneralUtility::trimExplode(',', $config['eval'], true);
84  $cols = MathUtility::forceIntegerInRange($config['cols'] ?: $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth);
85  $width = $this->formMaxWidth($cols);
86 
87  // Setting number of rows
88  $rows = MathUtility::forceIntegerInRange($config['rows'] ?: 5, 1, 20);
89  $originalRows = $rows;
90  $itemFormElementValueLength = strlen($itemValue);
91  if ($itemFormElementValueLength > $this->charactersPerRow * 2) {
93  round($itemFormElementValueLength / $this->charactersPerRow),
94  count(explode(LF, $itemValue)),
95  20
96  );
97  if ($rows < $originalRows) {
98  $rows = $originalRows;
99  }
100  }
101 
102  if ($config['readOnly']) {
103  $html = [];
104  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
105  $html[] = '<div class="form-wizards-wrap">';
106  $html[] = '<div class="form-wizards-element">';
107  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
108  $html[] = '<textarea class="form-control" rows="' . $rows . '" disabled>';
109  $html[] = htmlspecialchars($itemValue);
110  $html[] = '</textarea>';
111  $html[] = '</div>';
112  $html[] = '</div>';
113  $html[] = '</div>';
114  $html[] = '</div>';
115  $resultArray['html'] = implode(LF, $html);
116  return $resultArray;
117  }
118 
119  // @todo: The whole eval handling is a mess and needs refactoring
120  foreach ($evalList as $func) {
121  // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
122  // @todo: keyword like "date", or a class reference. The global registration could be dropped then
123  // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
124  // There is a similar hook for "evaluateFieldValue" in DataHandler and InputTextElement
125  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
126  if (class_exists($func)) {
127  $evalObj = GeneralUtility::makeInstance($func);
128  if (method_exists($evalObj, 'deevaluateFieldValue')) {
129  $_params = [
130  'value' => $itemValue
131  ];
132  $itemValue = $evalObj->deevaluateFieldValue($_params);
133  }
134  }
135  }
136  }
137 
138  $attributes = [
139  'id' => StringUtility::getUniqueId('formengine-textarea-'),
140  'name' => htmlspecialchars($parameterArray['itemFormElName']),
141  'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
142  'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']),
143  'rows' => $rows,
144  'wrap' => $config['wrap'] ?: 'virtual',
145  'onChange' => implode('', $parameterArray['fieldChangeFunc']),
146  ];
147  $classes = [
148  'form-control',
149  't3js-formengine-textarea',
150  'formengine-textarea',
151  ];
152  if ($config['fixedFont']) {
153  $classes[] = 'text-monospace';
154  }
155  if ($config['enableTabulator']) {
156  $classes[] = 't3js-enable-tab';
157  }
158  $attributes['class'] = implode(' ', $classes);
159  $maximumHeight = (int)$backendUser->uc['resizeTextareas_MaxHeight'];
160  if ($maximumHeight > 0) {
161  // add the max-height from the users' preference to it
162  $attributes['style'] = 'max-height: ' . $maximumHeight . 'px';
163  }
164  if (isset($config['max']) && (int)$config['max'] > 0) {
165  $attributes['maxlength'] = (int)$config['max'];
166  }
167  if (!empty($config['placeholder'])) {
168  $attributes['placeholder'] = htmlspecialchars(trim($config['placeholder']));
169  }
170 
171  $legacyWizards = $this->renderWizards();
172  $legacyFieldControlHtml = implode(LF, $legacyWizards['fieldControl']);
173  $legacyFieldWizardHtml = implode(LF, $legacyWizards['fieldWizard']);
174 
175  $fieldInformationResult = $this->renderFieldInformation();
176  $fieldInformationHtml = $fieldInformationResult['html'];
177  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
178 
179  $fieldControlResult = $this->renderFieldControl();
180  $fieldControlHtml = $legacyFieldControlHtml . $fieldControlResult['html'];
181  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
182 
183  $fieldWizardResult = $this->renderFieldWizard();
184  $fieldWizardHtml = $legacyFieldWizardHtml . $fieldWizardResult['html'];
185  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
186 
187  $html = [];
188  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
189  $html[] = $fieldInformationHtml;
190  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
191  $html[] = '<div class="form-wizards-wrap">';
192  $html[] = '<div class="form-wizards-element">';
193  $html[] = '<textarea ' . GeneralUtility::implodeAttributes($attributes, true) . '>' . htmlspecialchars($itemValue) . '</textarea>';
194  $html[] = '</div>';
195  $html[] = '<div class="form-wizards-items-aside">';
196  $html[] = '<div class="btn-group">';
197  $html[] = $fieldControlHtml;
198  $html[] = '</div>';
199  $html[] = '</div>';
200  $html[] = '<div class="form-wizards-items-bottom">';
201  $html[] = $fieldWizardHtml;
202  $html[] = '</div>';
203  $html[] = '</div>';
204  $html[] = '</div>';
205  $html[] = '</div>';
206 
207  $resultArray['html'] = implode(LF, $html);
208  return $resultArray;
209  }
210 
214  protected function getBackendUserAuthentication()
215  {
216  return $GLOBALS['BE_USER'];
217  }
218 }
static implodeAttributes(array $arr, $xhtmlSafe=false, $dontOmitBlankAttribs=false)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
renderWizards( $itemKinds=null, $wizConf=null, $table=null, $row=null, $fieldName=null, $PA=null, $itemName=null, $specConf=null, $RTE=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']