TYPO3 CMS  TYPO3_7-6
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 
20 
26 {
30  public $viewHelperMapping = [
31  'int' => 'renderIntegerField',
32  'int+' => 'renderPositiveIntegerField',
33  'integer' => 'renderIntegerField',
34  'color' => 'renderColorPicker',
35  'wrap' => 'renderWrapField',
36  'offset' => 'renderOffsetField',
37  'options' => 'renderOptionSelect',
38  'boolean' => 'renderCheckbox',
39  'user' => 'renderUserFunction',
40  'small' => 'renderSmallTextField',
41  'string' => 'renderTextField',
42  'input' => 'renderTextField', // only for backwards compatibility, many extensions depend on that
43  'default' => 'renderTextField' // only for backwards compatibility, many extensions depend on that
44  ];
45 
49  public $tagName = 'input';
50 
56  public function initializeArguments()
57  {
58  parent::initializeArguments();
59  $this->registerArgument('name', 'string', 'Name of input tag');
60  $this->registerArgument('value', 'mixed', 'Value of input tag');
62  }
63 
70  public function render(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
71  {
72  $input = '';
73  if (isset($this->viewHelperMapping[$configuration->getType()]) && method_exists($this, $this->viewHelperMapping[$configuration->getType()])) {
74  $input = $this->{$this->viewHelperMapping[$configuration->getType()]}($configuration);
75  } else {
76  $input = $this->{$this->viewHelperMapping['default']}($configuration);
77  }
78 
79  return $input;
80  }
81 
88  protected function renderColorPicker(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
89  {
90  $elementId = 'em-' . $configuration->getName();
91  $elementName = $this->getName($configuration);
92 
93  // configure the field
94  $this->tag->setTagName('input');
95  $this->tag->addAttribute('type', 'text');
96  $this->tag->addAttribute('id', $elementId);
97  $this->tag->addAttribute('name', $elementName);
98  $this->tag->addAttribute('data-formengine-input-name', $elementName);
99  $this->tag->addAttribute('class', 'form-control');
100  if ($configuration->getValue() !== null) {
101  $this->tag->addAttribute('value', $configuration->getValue());
102  }
103 
104  // configure colorpicker wizard
105  $params = [
106  'formName' => 'configurationform',
107  'itemName' => $elementName,
108  ];
109  $onClick =
110  'this.blur();' .
111  'vHWin=window.open(' .
112  GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('wizard_colorpicker', ['P' => $params])) . ' + \'&P[currentValue]=\' + encodeURIComponent(document.getElementById(' . GeneralUtility::quoteJSvalue($elementId) . ').value),' .
113  '\'popUpem-' . GeneralUtility::shortmd5($elementName) . '\',' .
114  '\'height=400,width=400,status=0,menubar=0,scrollbars=1\'' .
115  ');' .
116  'vHWin.focus();' .
117  'return false;';
118 
119  // wrap the field
120  $output = '<div class="form-wizards-wrap form-wizards-aside">'
121  . '<div class="form-wizards-element">' . $this->tag->render() . '</div>'
122  . '<div class="form-wizards-items"><a href="#" onClick="' . htmlspecialchars($onClick) . '" class="btn btn-default"><span class="t3-icon fa fa-eyedropper"></span></a></div>'
123  . '</div>';
124 
125  return $output;
126  }
127 
134  protected function renderOffsetField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
135  {
136  $this->tag->setTagName('input');
137  $this->tag->addAttribute('type', 'text');
138  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
139  $this->tag->addAttribute('name', $this->getName($configuration));
140  $this->tag->addAttribute('class', 'form-control t3js-emconf-offset');
141  if ($configuration->getValue() !== null) {
142  $this->tag->addAttribute('value', $configuration->getValue());
143  }
144  return $this->tag->render();
145  }
146 
153  protected function renderWrapField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
154  {
155  $this->tag->setTagName('input');
156  $this->tag->addAttribute('type', 'text');
157  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
158  $this->tag->addAttribute('name', $this->getName($configuration));
159  $this->tag->addAttribute('class', 'form-control t3js-emconf-wrap');
160  if ($configuration->getValue() !== null) {
161  $this->tag->addAttribute('value', $configuration->getValue());
162  }
163  return $this->tag->render();
164  }
165 
172  protected function renderOptionSelect(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
173  {
174  $this->tag->setTagName('select');
175  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
176  $this->tag->addAttribute('name', $this->getName($configuration));
177  $this->tag->addAttribute('class', 'form-control');
178  $optionValueArray = $configuration->getGeneric();
179  $output = '';
180  foreach ($optionValueArray as $label => $value) {
181  $output .= '<option value="' . htmlspecialchars($value) . '"';
182  if ($configuration->getValue() == $value) {
183  $output .= ' selected="selected"';
184  }
185  $output .= '>' . $GLOBALS['LANG']->sL($label, true) . '</option>';
186  }
187  $this->tag->setContent($output);
188  return $this->tag->render();
189  }
190 
197  protected function renderPositiveIntegerField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
198  {
199  $this->tag->setTagName('input');
200  $this->tag->addAttribute('type', 'number');
201  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
202  $this->tag->addAttribute('name', $this->getName($configuration));
203  $this->tag->addAttribute('class', 'form-control');
204  $this->tag->addAttribute('min', '0');
205  if ($configuration->getValue() !== null) {
206  $this->tag->addAttribute('value', $configuration->getValue());
207  }
208  return $this->tag->render();
209  }
210 
217  protected function renderIntegerField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
218  {
219  $this->tag->setTagName('input');
220  $this->tag->addAttribute('type', 'number');
221  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
222  $this->tag->addAttribute('name', $this->getName($configuration));
223  $this->tag->addAttribute('class', 'form-control');
224  if ($configuration->getValue() !== null) {
225  $this->tag->addAttribute('value', $configuration->getValue());
226  }
227  return $this->tag->render();
228  }
229 
236  protected function renderTextField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
237  {
238  $this->tag->setTagName('input');
239  $this->tag->addAttribute('type', 'text');
240  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
241  $this->tag->addAttribute('name', $this->getName($configuration));
242  $this->tag->addAttribute('class', 'form-control');
243  if ($configuration->getValue() !== null) {
244  $this->tag->addAttribute('value', $configuration->getValue());
245  }
246  return $this->tag->render();
247  }
248 
255  protected function renderSmallTextField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
256  {
257  return $this->renderTextField($configuration);
258  }
259 
266  public function renderCheckbox(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
267  {
268  $this->tag->addAttribute('type', 'checkbox');
269  $this->tag->addAttribute('name', $this->getName($configuration));
270  $this->tag->addAttribute('value', 1);
271  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
272  if ($configuration->getValue() == 1) {
273  $this->tag->addAttribute('checked', 'checked');
274  }
275  $hiddenField = $this->renderHiddenFieldForEmptyValue($configuration);
276  return '<div class="checkbox">' . $hiddenField . '<label>' . $this->tag->render() . '</label></div>';
277  }
278 
285  protected function renderUserFunction(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
286  {
287  $userFunction = $configuration->getGeneric();
288  $userFunctionParams = [
289  'fieldName' => $this->getName($configuration),
290  'fieldValue' => $configuration->getValue(),
291  'propertyName' => $configuration->getName()
292  ];
293  return \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($userFunction, $userFunctionParams, $this, '');
294  }
295 
302  protected function getName(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
303  {
304  return 'tx_extensionmanager_tools_extensionmanagerextensionmanager[config][' . $configuration->getName() . '][value]';
305  }
306 
313  protected function renderHiddenFieldForEmptyValue($configuration)
314  {
315  $hiddenFieldNames = [];
316  if ($this->viewHelperVariableContainer->exists(FormViewHelper::class, 'renderedHiddenFields')) {
317  $hiddenFieldNames = $this->viewHelperVariableContainer->get(FormViewHelper::class, 'renderedHiddenFields');
318  }
319  $fieldName = $this->getName($configuration);
320  if (substr($fieldName, -2) === '[]') {
321  $fieldName = substr($fieldName, 0, -2);
322  }
323  if (!in_array($fieldName, $hiddenFieldNames)) {
324  $hiddenFieldNames[] = $fieldName;
325  $this->viewHelperVariableContainer->addOrUpdate(FormViewHelper::class, 'renderedHiddenFields', $hiddenFieldNames);
326  return '<input type="hidden" name="' . htmlspecialchars($fieldName) . '" value="0" />';
327  }
328  return '';
329  }
330 }
renderOptionSelect(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderUserFunction(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderSmallTextField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
registerArgument($name, $type, $description, $required=false, $defaultValue=null)
renderCheckbox(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
getName(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
render(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderWrapField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderTextField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderIntegerField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderOffsetField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
renderPositiveIntegerField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderColorPicker(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)