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