‪TYPO3CMS  11.5
TextTableElement.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use TYPO3\CMS\Backend\Form\Behavior\OnFieldChangeTrait;
26 
32 {
33  use OnFieldChangeTrait;
34 
38  protected int ‪$numNewRows = 1;
39 
45  protected ‪$defaultFieldInformation = [
46  'tcaDescription' => [
47  'renderType' => 'tcaDescription',
48  ],
49  ];
50 
56  protected ‪$defaultFieldWizard = [
57  'localizationStateSelector' => [
58  'renderType' => 'localizationStateSelector',
59  ],
60  'otherLanguageContent' => [
61  'renderType' => 'otherLanguageContent',
62  'after' => [
63  'localizationStateSelector',
64  ],
65  ],
66  'defaultLanguageDifferences' => [
67  'renderType' => 'defaultLanguageDifferences',
68  'after' => [
69  'otherLanguageContent',
70  ],
71  ],
72  ];
73 
80  protected ‪$charactersPerRow = 40;
81 
87  public function ‪render()
88  {
89  $backendUser = $this->‪getBackendUserAuthentication();
90 
91  $parameterArray = $this->data['parameterArray'];
92  $resultArray = $this->‪initializeResultArray();
93 
94  $itemValue = $parameterArray['itemFormElValue'];
95  $config = $parameterArray['fieldConf']['config'];
96  $evalList = ‪GeneralUtility::trimExplode(',', $config['eval'] ?? '', true);
97 
98  // Setting number of rows
99  $rows = $config['rows'] ?? 0;
100  $rows = ‪MathUtility::forceIntegerInRange($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'] ?? false) {
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="overflow: auto;">';
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 = array_merge(
158  [
159  'id' => $fieldId,
160  'name' => htmlspecialchars($parameterArray['itemFormElName']),
161  'data-formengine-validation-rules' => $this->‪getValidationDataAsJsonString($config),
162  'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']),
163  'rows' => (string)$rows,
164  'wrap' => (string)(($config['wrap'] ?? 'virtual') ?: 'virtual'),
165  'hidden' => 'true',
166  ],
167  $this->getOnFieldChangeAttrs('change', $parameterArray['fieldChangeFunc'] ?? [])
168  );
169  $classes = [
170  'form-control',
171  't3js-formengine-textarea',
172  'formengine-textarea',
173  ];
174  if ($config['fixedFont'] ?? false) {
175  $classes[] = 'text-monospace';
176  }
177  if ($config['enableTabulator'] ?? false) {
178  $classes[] = 't3js-enable-tab';
179  }
180  $attributes['class'] = implode(' ', $classes);
181  $maximumHeight = (int)$backendUser->uc['resizeTextareas_MaxHeight'];
182  ‪if ($maximumHeight > 0) {
183  // add the max-height from the users' preference to it
184  $attributes['style'] = 'max-height: ' . $maximumHeight . 'px';
185  }
186  if (isset($config['max']) && (int)$config['max'] > 0) {
187  $attributes['maxlength'] = (string)(int)$config['max'];
188  }
189  if (!empty($config['placeholder'])) {
190  $attributes['placeholder'] = htmlspecialchars(trim($config['placeholder']));
191  }
192 
193  $fieldControlResult = $this->‪renderFieldControl();
194  $fieldControlHtml = $fieldControlResult['html'];
195  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
196 
197  $fieldWizardResult = $this->‪renderFieldWizard();
198  $fieldWizardHtml = $fieldWizardResult['html'];
199  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
200 
201  $html = [];
202  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
203  $html[] = $fieldInformationHtml;
204  $html[] = '<div class="form-control-wrap" style="overflow: auto">';
205  $html[] = '<div class="form-wizards-wrap">';
206  $html[] = $this->‪getTableWizard($attributes['id']);
207  $html[] = '<div>';
208  $html[] = '<textarea ' . GeneralUtility::implodeAttributes($attributes, true) . '>' . htmlspecialchars($itemValue) . '</textarea>';
209  $html[] = '</div>';
210  if (!empty($fieldControlHtml)) {
211  $html[] = '<div class="form-wizards-items-aside form-wizards-items-aside--field-control">';
212  $html[] = '<div class="btn-group">';
213  $html[] = $fieldControlHtml;
214  $html[] = '</div>';
215  $html[] = '</div>';
216  }
217  if (!empty($fieldWizardHtml)) {
218  $html[] = '<div class="form-wizards-items-bottom">';
219  $html[] = $fieldWizardHtml;
220  $html[] = '</div>';
221  }
222  $html[] = '</div>';
223  $html[] = '</div>';
224  $html[] = '</div>';
225 
226  $resultArray['requireJsModules'][] = ‪JavaScriptModuleInstruction::forRequireJS(
227  'TYPO3/CMS/Backend/FormEngine/Element/TextTableElement'
228  )->instance($fieldId);
229 
230  $resultArray['requireJsModules'][] = ‪JavaScriptModuleInstruction::forRequireJS('TYPO3/CMS/Backend/Element/TableWizardElement');
231  $resultArray['additionalInlineLanguageLabelFiles'][] = 'EXT:core/Resources/Private/Language/locallang_wizards.xlf';
232 
233  $resultArray['html'] = implode(LF, $html);
234  return $resultArray;
235  }
236 
240  protected function ‪getBackendUserAuthentication()
241  {
242  return ‪$GLOBALS['BE_USER'];
243  }
244 
250  protected function ‪getTableWizard(string $dataId): string
251  {
252  $row = $this->data['databaseRow'];
253  $delimiter = ($row['table_delimiter'][0] ?? false) ? chr((int)$row['table_delimiter'][0]) : '|';
254  $enclosure = ($row['table_enclosure'][0] ?? false) ? chr((int)$row['table_enclosure'][0]) : '';
255 
256  return sprintf(
257  '<typo3-backend-table-wizard %s></typo3-backend-table-wizard>',
258  GeneralUtility::implodeAttributes([
259  'type' => 'input',
260  'append-rows' => (string)$this->numNewRows,
261  'selector' => '#' . $dataId,
262  'delimiter' => $delimiter,
263  'enclosure' => $enclosure,
264  ], true)
265  );
266  }
267 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:76
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:120
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Backend\Form\Element\TextTableElement\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: TextTableElement.php:236
‪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:43
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:35
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\forRequireJS
‪static self forRequireJS(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:49
‪TYPO3\CMS\Backend\Form\Element\TextTableElement\getTableWizard
‪string getTableWizard(string $dataId)
Definition: TextTableElement.php:246
‪TYPO3\CMS\Backend\Form\AbstractNode\getValidationDataAsJsonString
‪string getValidationDataAsJsonString(array $config)
Definition: AbstractNode.php:156
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldControl
‪array renderFieldControl()
Definition: AbstractFormElement.php:92
‪TYPO3\CMS\Backend\Form\Element\TextTableElement\$numNewRows
‪int $numNewRows
Definition: TextTableElement.php:37
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Form\Element\TextTableElement
Definition: TextTableElement.php:32
‪TYPO3\CMS\Backend\Form\Element\TextTableElement\render
‪array render()
Definition: TextTableElement.php:83
‪TYPO3\CMS\Backend\Form\Element\TextTableElement\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: TextTableElement.php:53
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:128
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪if
‪if(PHP_SAPI !=='cli')
Definition: checkNamespaceIntegrity.php:25
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldWizard
‪array renderFieldWizard()
Definition: AbstractFormElement.php:108
‪TYPO3\CMS\Backend\Form\Element\TextTableElement\$charactersPerRow
‪int $charactersPerRow
Definition: TextTableElement.php:76