TYPO3 CMS  TYPO3_8-7
InputColorPickerElement.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  public function render()
56  {
57  $languageService = $this->getLanguageService();
58 
59  $table = $this->data['tableName'];
60  $fieldName = $this->data['fieldName'];
61  $row = $this->data['databaseRow'];
62  $parameterArray = $this->data['parameterArray'];
63  $resultArray = $this->initializeResultArray();
64 
65  $itemValue = $parameterArray['itemFormElValue'];
66  $config = $parameterArray['fieldConf']['config'];
67  $size = MathUtility::forceIntegerInRange($config['size'] ?: $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth);
68  $evalList = GeneralUtility::trimExplode(',', $config['eval'], true);
69  $width = (int)$this->formMaxWidth($size);
70  $nullControlNameEscaped = htmlspecialchars('control[active][' . $table . '][' . $row['uid'] . '][' . $fieldName . ']');
71 
72  if ($config['readOnly']) {
73  $html = [];
74  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
75  $html[] = '<div class="form-wizards-wrap">';
76  $html[] = '<div class="form-wizards-element">';
77  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
78  $html[] = '<input class="form-control" value="' . htmlspecialchars($itemValue) . '" type="text" disabled>';
79  $html[] = '</div>';
80  $html[] = '</div>';
81  $html[] = '</div>';
82  $html[] = '</div>';
83  $resultArray['html'] = implode(LF, $html);
84  return $resultArray;
85  }
86 
87  // @todo: The whole eval handling is a mess and needs refactoring
88  foreach ($evalList as $func) {
89  // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
90  // @todo: keyword like "date", or a class reference. The global registration could be dropped then
91  // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
92  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
93  if (class_exists($func)) {
94  $evalObj = GeneralUtility::makeInstance($func);
95  if (method_exists($evalObj, 'deevaluateFieldValue')) {
96  $_params = [
97  'value' => $itemValue
98  ];
99  $itemValue = $evalObj->deevaluateFieldValue($_params);
100  }
101  if (method_exists($evalObj, 'returnFieldJS')) {
102  $resultArray['additionalJavaScriptPost'][] = 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($evalData) . '] = function(value) {' . $evalObj->returnFieldJS() . '};';
103  }
104  }
105  }
106  }
107 
108  // Load needed js library
109  $resultArray['requireJsModules'][] = [
110  'TYPO3/CMS/Backend/ColorPicker' => 'function(ColorPicker){ColorPicker.initialize()}'
111  ];
112 
113  $attributes = [
114  'value' => $itemValue,
115  'id' => StringUtility::getUniqueId('formengine-input-'),
116  'class' => implode(' ', [
117  'form-control',
118  'hasDefaultValue',
119  't3js-clearable',
120  't3js-color-picker',
121  'formengine-colorpickerelement',
122  ]),
123  'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
124  'data-formengine-input-params' => json_encode([
125  'field' => $parameterArray['itemFormElName'],
126  'evalList' => implode(',', $evalList),
127  'is_in' => trim($config['is_in']),
128  ]),
129  'data-formengine-input-name' => $parameterArray['itemFormElName'],
130  ];
131 
132  if (isset($config['max']) && (int)$config['max'] > 0) {
133  $attributes['maxlength'] = (int)$config['max'];
134  }
135  if (!empty($config['placeholder'])) {
136  $attributes['placeholder'] = trim($config['placeholder']);
137  }
138  if (isset($config['autocomplete'])) {
139  $attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on';
140  }
141 
142  $valuePickerHtml = [];
143  if (isset($config['valuePicker']['items']) && is_array($config['valuePicker']['items'])) {
144  $valuePickerHtml[] = '<select class="t3js-colorpicker-value-trigger form-control tceforms-select tceforms-wizardselect">';
145  $valuePickerHtml[] = '<option></option>';
146  foreach ($config['valuePicker']['items'] as $item) {
147  $valuePickerHtml[] = '<option value="' . htmlspecialchars($item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>';
148  }
149  $valuePickerHtml[] = '</select>';
150  }
151 
152  $legacyWizards = $this->renderWizards();
153  $legacyFieldControlHtml = implode(LF, $legacyWizards['fieldControl']);
154  $legacyFieldWizardHtml = implode(LF, $legacyWizards['fieldWizard']);
155 
156  $fieldInformationResult = $this->renderFieldInformation();
157  $fieldInformationHtml = $fieldInformationResult['html'];
158  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
159 
160  $fieldWizardResult = $this->renderFieldWizard();
161  $fieldWizardHtml = $legacyFieldWizardHtml . $fieldWizardResult['html'];
162  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
163 
164  $fieldControlResult = $this->renderFieldControl();
165  $fieldControlHtml = $legacyFieldControlHtml . $fieldControlResult['html'];
166  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
167 
168  $mainFieldHtml = [];
169  $mainFieldHtml[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
170  $mainFieldHtml[] = '<div class="form-wizards-wrap">';
171  $mainFieldHtml[] = '<div class="form-wizards-element">';
172  $mainFieldHtml[] = '<input type="text"' . GeneralUtility::implodeAttributes($attributes, true) . ' />';
173  $mainFieldHtml[] = '<input type="hidden" name="' . $parameterArray['itemFormElName'] . '" value="' . htmlspecialchars($itemValue) . '" />';
174  $mainFieldHtml[] = '</div>';
175  $mainFieldHtml[] = '<div class="form-wizards-items-aside">';
176  $mainFieldHtml[] = '<div class="btn-group">';
177  $mainFieldHtml[] = $fieldControlHtml;
178  $mainFieldHtml[] = implode(LF, $valuePickerHtml);
179  $mainFieldHtml[] = '</div>';
180  $mainFieldHtml[] = '</div>';
181  $mainFieldHtml[] = '<div class="form-wizards-items-bottom">';
182  $mainFieldHtml[] = $fieldWizardHtml;
183  $mainFieldHtml[] = '</div>';
184  $mainFieldHtml[] = '</div>';
185  $mainFieldHtml[] = '</div>';
186  $mainFieldHtml = implode(LF, $mainFieldHtml);
187 
188  $fullElement = $mainFieldHtml;
189  if ($this->hasNullCheckboxButNoPlaceholder()) {
190  $checked = $itemValue !== null ? ' checked="checked"' : '';
191  $fullElement = [];
192  $fullElement[] = '<div class="t3-form-field-disable"></div>';
193  $fullElement[] = '<div class="checkbox t3-form-field-eval-null-checkbox">';
194  $fullElement[] = '<label for="' . $nullControlNameEscaped . '">';
195  $fullElement[] = '<input type="hidden" name="' . $nullControlNameEscaped . '" value="0" />';
196  $fullElement[] = '<input type="checkbox" name="' . $nullControlNameEscaped . '" id="' . $nullControlNameEscaped . '" value="1"' . $checked . ' />';
197  $fullElement[] = $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.nullCheckbox');
198  $fullElement[] = '</label>';
199  $fullElement[] = '</div>';
200  $fullElement[] = $mainFieldHtml;
201  $fullElement = implode(LF, $fullElement);
202  } elseif ($this->hasNullCheckboxWithPlaceholder()) {
203  $checked = $itemValue !== null ? ' checked="checked"' : '';
204  $placeholder = $shortenedPlaceholder = $config['placeholder'] ?? '';
205  $disabled = '';
206  $fallbackValue = 0;
207  if (strlen($placeholder) > 0) {
208  $shortenedPlaceholder = GeneralUtility::fixed_lgd_cs($placeholder, 20);
209  if ($placeholder !== $shortenedPlaceholder) {
210  $overrideLabel = sprintf(
211  $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'),
212  '<span title="' . htmlspecialchars($placeholder) . '">' . htmlspecialchars($shortenedPlaceholder) . '</span>'
213  );
214  } else {
215  $overrideLabel = sprintf(
216  $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'),
217  htmlspecialchars($placeholder)
218  );
219  }
220  } else {
221  $overrideLabel = $languageService->sL(
222  'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override_not_available'
223  );
224  }
225  $fullElement = [];
226  $fullElement[] = '<div class="checkbox t3js-form-field-eval-null-placeholder-checkbox">';
227  $fullElement[] = '<label for="' . $nullControlNameEscaped . '">';
228  $fullElement[] = '<input type="hidden" name="' . $nullControlNameEscaped . '" value="' . $fallbackValue . '" />';
229  $fullElement[] = '<input type="checkbox" name="' . $nullControlNameEscaped . '" id="' . $nullControlNameEscaped . '" value="1"' . $checked . $disabled . ' />';
230  $fullElement[] = $overrideLabel;
231  $fullElement[] = '</label>';
232  $fullElement[] = '</div>';
233  $fullElement[] = '<div class="t3js-formengine-placeholder-placeholder">';
234  $fullElement[] = '<div class="form-control-wrap" style="max-width:' . $width . 'px">';
235  $fullElement[] = '<input type="text" class="form-control" disabled="disabled" value="' . $shortenedPlaceholder . '" />';
236  $fullElement[] = '</div>';
237  $fullElement[] = '</div>';
238  $fullElement[] = '<div class="t3js-formengine-placeholder-formfield">';
239  $fullElement[] = $mainFieldHtml;
240  $fullElement[] = '</div>';
241  $fullElement = implode(LF, $fullElement);
242  }
243 
244  $resultArray['html'] = '<div class="formengine-field-item t3js-formengine-field-item">' . $fieldInformationHtml . $fullElement . '</div>';
245  return $resultArray;
246  }
247 
251  protected function getLanguageService()
252  {
253  return $GLOBALS['LANG'];
254  }
255 }
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)
static fixed_lgd_cs($string, $chars, $appendString='...')
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']