TYPO3 CMS  TYPO3_8-7
TypoScriptConstantsViewHelper.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 
19 
25 {
29  public $viewHelperMapping = [
30  'int' => 'renderIntegerField',
31  'int+' => 'renderPositiveIntegerField',
32  'integer' => 'renderIntegerField',
33  'color' => 'renderColorPicker',
34  'wrap' => 'renderWrapField',
35  'offset' => 'renderOffsetField',
36  'options' => 'renderOptionSelect',
37  'boolean' => 'renderCheckbox',
38  'user' => 'renderUserFunction',
39  'small' => 'renderSmallTextField',
40  'string' => 'renderTextField',
41  'input' => 'renderTextField', // only for backwards compatibility, many extensions depend on that
42  'default' => 'renderTextField' // only for backwards compatibility, many extensions depend on that
43  ];
44 
48  public $tagName = 'input';
49 
53  public function initializeArguments()
54  {
55  parent::initializeArguments();
56  $this->registerArgument('name', 'string', 'Name of input tag');
57  $this->registerArgument('value', 'mixed', 'Value of input tag');
58  $this->registerArgument('configuration', ConfigurationItem::class, '', true);
60  }
61 
67  public function render()
68  {
70  $configuration = $this->arguments['configuration'];
71  if (isset($this->viewHelperMapping[$configuration->getType()]) && method_exists($this, $this->viewHelperMapping[$configuration->getType()])) {
72  $input = $this->{$this->viewHelperMapping[$configuration->getType()]}($configuration);
73  } else {
74  $input = $this->{$this->viewHelperMapping['default']}($configuration);
75  }
76 
77  return $input;
78  }
79 
86  protected function renderColorPicker(ConfigurationItem $configuration)
87  {
88  $elementId = 'em-' . $configuration->getName();
89  $elementName = $this->getName($configuration);
90 
91  // configure the field
92  $this->tag->setTagName('input');
93  $this->tag->addAttribute('type', 'text');
94  $this->tag->addAttribute('id', $elementId);
95  $this->tag->addAttribute('name', $elementName);
96  $this->tag->addAttribute('data-formengine-input-name', $elementName);
97  $this->tag->addAttribute('class', 'form-control');
98  if ($configuration->getValue() !== null) {
99  $this->tag->addAttribute('value', $configuration->getValue());
100  }
101 
102  $output = '
103  <div class="form-wizards-element">
104  <input class="form-control t3js-color-input formengine-colorpickerelement t3js-color-picker" type="text"
105  name="' . htmlspecialchars($elementName) . '" value="' . $this->tag->getAttribute('value') . '"/>
106  <script type="text/javascript">
107  require([\'TYPO3/CMS/Backend/ColorPicker\'], function(ColorPicker){ColorPicker.initialize()});
108  </script>
109  </div>';
110 
111  return $output;
112  }
113 
120  protected function renderOffsetField(ConfigurationItem $configuration)
121  {
122  $this->tag->setTagName('input');
123  $this->tag->addAttribute('type', 'text');
124  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
125  $this->tag->addAttribute('name', $this->getName($configuration));
126  $this->tag->addAttribute('class', 'form-control t3js-emconf-offset');
127  if ($configuration->getValue() !== null) {
128  $this->tag->addAttribute('value', $configuration->getValue());
129  }
130  return $this->tag->render();
131  }
132 
139  protected function renderWrapField(ConfigurationItem $configuration)
140  {
141  $this->tag->setTagName('input');
142  $this->tag->addAttribute('type', 'text');
143  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
144  $this->tag->addAttribute('name', $this->getName($configuration));
145  $this->tag->addAttribute('class', 'form-control t3js-emconf-wrap');
146  if ($configuration->getValue() !== null) {
147  $this->tag->addAttribute('value', $configuration->getValue());
148  }
149  return $this->tag->render();
150  }
151 
158  protected function renderOptionSelect(ConfigurationItem $configuration)
159  {
160  $this->tag->setTagName('select');
161  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
162  $this->tag->addAttribute('name', $this->getName($configuration));
163  $this->tag->addAttribute('class', 'form-control');
164  $optionValueArray = $configuration->getGeneric();
165  $output = '';
166  foreach ($optionValueArray as $label => $value) {
167  $output .= '<option value="' . htmlspecialchars($value) . '"';
168  if ($configuration->getValue() == $value) {
169  $output .= ' selected="selected"';
170  }
171  $output .= '>' . htmlspecialchars($GLOBALS['LANG']->sL($label)) . '</option>';
172  }
173  $this->tag->setContent($output);
174  return $this->tag->render();
175  }
176 
183  protected function renderPositiveIntegerField(ConfigurationItem $configuration)
184  {
185  $this->tag->setTagName('input');
186  $this->tag->addAttribute('type', 'number');
187  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
188  $this->tag->addAttribute('name', $this->getName($configuration));
189  $this->tag->addAttribute('class', 'form-control');
190  $this->tag->addAttribute('min', '0');
191  if ($configuration->getValue() !== null) {
192  $this->tag->addAttribute('value', $configuration->getValue());
193  }
194  return $this->tag->render();
195  }
196 
203  protected function renderIntegerField(ConfigurationItem $configuration)
204  {
205  $this->tag->setTagName('input');
206  $this->tag->addAttribute('type', 'number');
207  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
208  $this->tag->addAttribute('name', $this->getName($configuration));
209  $this->tag->addAttribute('class', 'form-control');
210  if ($configuration->getValue() !== null) {
211  $this->tag->addAttribute('value', $configuration->getValue());
212  }
213  return $this->tag->render();
214  }
215 
222  protected function renderTextField(ConfigurationItem $configuration)
223  {
224  $this->tag->setTagName('input');
225  $this->tag->addAttribute('type', 'text');
226  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
227  $this->tag->addAttribute('name', $this->getName($configuration));
228  $this->tag->addAttribute('class', 'form-control');
229  if ($configuration->getValue() !== null) {
230  $this->tag->addAttribute('value', $configuration->getValue());
231  }
232  return $this->tag->render();
233  }
234 
241  protected function renderSmallTextField(ConfigurationItem $configuration)
242  {
243  return $this->renderTextField($configuration);
244  }
245 
252  public function renderCheckbox(ConfigurationItem $configuration)
253  {
254  $this->tag->addAttribute('type', 'checkbox');
255  $this->tag->addAttribute('name', $this->getName($configuration));
256  $this->tag->addAttribute('value', 1);
257  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
258  if ($configuration->getValue() == 1) {
259  $this->tag->addAttribute('checked', 'checked');
260  }
261  $hiddenField = $this->renderHiddenFieldForEmptyValue($configuration);
262  return '<div class="checkbox">' . $hiddenField . '<label>' . $this->tag->render() . '</label></div>';
263  }
264 
271  protected function renderUserFunction(ConfigurationItem $configuration)
272  {
273  $userFunction = $configuration->getGeneric();
274  $userFunctionParams = [
275  'fieldName' => $this->getName($configuration),
276  'fieldValue' => $configuration->getValue(),
277  'propertyName' => $configuration->getName()
278  ];
279  return \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($userFunction, $userFunctionParams, $this);
280  }
281 
288  protected function getName(ConfigurationItem $configuration)
289  {
290  return 'tx_extensionmanager_tools_extensionmanagerextensionmanager[config][' . $configuration->getName() . '][value]';
291  }
292 
299  protected function renderHiddenFieldForEmptyValue($configuration)
300  {
301  $hiddenFieldNames = [];
302  if ($this->viewHelperVariableContainer->exists(FormViewHelper::class, 'renderedHiddenFields')) {
303  $hiddenFieldNames = $this->viewHelperVariableContainer->get(FormViewHelper::class, 'renderedHiddenFields');
304  }
305  $fieldName = $this->getName($configuration);
306  if (substr($fieldName, -2) === '[]') {
307  $fieldName = substr($fieldName, 0, -2);
308  }
309  if (!in_array($fieldName, $hiddenFieldNames)) {
310  $hiddenFieldNames[] = $fieldName;
311  $this->viewHelperVariableContainer->addOrUpdate(FormViewHelper::class, 'renderedHiddenFields', $hiddenFieldNames);
312  return '<input type="hidden" name="' . htmlspecialchars($fieldName) . '" value="0" />';
313  }
314  return '';
315  }
316 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']