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