TYPO3 CMS  TYPO3_6-2
TypoScriptConstantsViewHelper.php
Go to the documentation of this file.
1 <?php
3 
22 
23  public $viewHelperMapping = array(
24  'int' => 'renderIntegerField',
25  'int+' => 'renderPositiveIntegerField',
26  'integer' => 'renderIntegerField',
27  'color' => 'renderColorPicker',
28  'wrap' => 'renderWrapField',
29  'offset' => 'renderOffsetField',
30  'options' => 'renderOptionSelect',
31  'boolean' => 'renderCheckbox',
32  'user' => 'renderUserFunction',
33  'small' => 'renderSmallTextField',
34  'string' => 'renderTextField',
35  'input' => 'renderTextField', // only for backwards compatibility, many extensions depend on that
36  'default' => 'renderTextField' // only for backwards compatibility, many extensions depend on that
37  );
38 
39  public $tagName = 'input';
40 
46  public function initializeArguments() {
47  parent::initializeArguments();
48  $this->registerArgument('name', 'string', 'Name of input tag');
49  $this->registerArgument('value', 'mixed', 'Value of input tag');
51  }
52 
59  public function render(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
60  $input = '';
61  if (isset($this->viewHelperMapping[$configuration->getType()]) && method_exists($this, $this->viewHelperMapping[$configuration->getType()])) {
62  $input = $this->{$this->viewHelperMapping[$configuration->getType()]}($configuration);
63  } else {
64  $input = $this->{$this->viewHelperMapping['default']}($configuration);
65  }
66 
67  return $input;
68  }
69 
76  protected function renderColorPicker(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
77  $this->tag->setTagName('input');
78  $this->tag->addAttribute('type', 'text');
79  $this->tag->addAttribute('name', $this->getName($configuration));
80  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
81  $doc = $this->getDocInstance();
82  $pageRenderer = $doc->getPageRenderer();
83  $pageRenderer->addCssFile('sysext/extensionmanager/Resources/Public/Contrib/Farbtastic/farbtastic.css');
84  $pageRenderer->addJsFile('sysext/extensionmanager/Resources/Public/Contrib/Farbtastic/farbtastic.js');
85  $pageRenderer->addJsInlineCode('colorpicker', '
86  jQuery(document).ready(function() {
87  jQuery(".colorPicker").farbtastic("#em-' . $configuration->getName() . '");
88  });
89  ');
90  if ($configuration->getValue() !== NULL) {
91  $this->tag->addAttribute('value', $configuration->getValue());
92  }
93  return $this->tag->render() . '<div class="colorPicker"></div>';
94  }
95 
102  protected function renderOffsetField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
103  $this->tag->setTagName('input');
104  $this->tag->addAttribute('type', 'text');
105  $this->tag->addAttribute('name', $this->getName($configuration));
106  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
107  $this->tag->addAttribute('class', 'offset');
108  if ($configuration->getValue() !== NULL) {
109  $this->tag->addAttribute('value', $configuration->getValue());
110  }
111  return $this->tag->render();
112  }
113 
120  protected function renderWrapField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
121  $this->tag->setTagName('input');
122  $this->tag->addAttribute('type', 'text');
123  $this->tag->addAttribute('name', $this->getName($configuration));
124  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
125  $this->tag->addAttribute('class', 'wrap');
126  if ($configuration->getValue() !== NULL) {
127  $this->tag->addAttribute('value', $configuration->getValue());
128  }
129  return $this->tag->render();
130  }
131 
138  protected function renderOptionSelect(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
139  $this->tag->addAttribute('name', $this->getName($configuration));
140  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
141  $this->tag->setTagName('select');
142  $optionValueArray = $configuration->getGeneric();
143  $output = '';
144  foreach ($optionValueArray as $label => $value) {
145  $output .= '<option value="' . htmlspecialchars($value) . '"';
146  if ($configuration->getValue() == $value) {
147  $output .= ' selected="selected"';
148  }
149  $output .= '>' . $GLOBALS['LANG']->sL($label, TRUE) . '</option>';
150  }
151  $this->tag->setContent($output);
152  return $this->tag->render();
153  }
154 
161  protected function renderPositiveIntegerField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
162  $this->tag->setTagName('input');
163  $this->tag->addAttribute('type', 'number');
164  $this->tag->addAttribute('min', '0');
165  $this->tag->addAttribute('name', $this->getName($configuration));
166  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
167  if ($configuration->getValue() !== NULL) {
168  $this->tag->addAttribute('value', $configuration->getValue());
169  }
170  return $this->tag->render();
171  }
172 
179  protected function renderIntegerField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
180  $this->tag->setTagName('input');
181  $this->tag->addAttribute('type', 'number');
182  $this->tag->addAttribute('name', $this->getName($configuration));
183  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
184  if ($configuration->getValue() !== NULL) {
185  $this->tag->addAttribute('value', $configuration->getValue());
186  }
187  return $this->tag->render();
188  }
189 
196  protected function renderTextField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
197  $this->tag->setTagName('input');
198  $this->tag->addAttribute('type', 'text');
199  $this->tag->addAttribute('name', $this->getName($configuration));
200  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
201  if ($configuration->getValue() !== NULL) {
202  $this->tag->addAttribute('value', $configuration->getValue());
203  }
204  return $this->tag->render();
205  }
206 
213  protected function renderSmallTextField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
214  $this->tag->addAttribute('class', 'small');
215  return $this->renderTextField($configuration);
216  }
217 
224  public function renderCheckbox(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
225  $this->tag->addAttribute('type', 'checkbox');
226  $this->tag->addAttribute('name', $this->getName($configuration));
227  $this->tag->addAttribute('value', 1);
228  $this->tag->addAttribute('id', 'em-' . $configuration->getName());
229  if ($configuration->getValue() == 1) {
230  $this->tag->addAttribute('checked', 'checked');
231  }
232  $hiddenField = $this->renderHiddenFieldForEmptyValue($configuration);
233  return $hiddenField . $this->tag->render();
234  }
235 
242  protected function renderUserFunction(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
243  $userFunction = $configuration->getGeneric();
244  $userFunctionParams = array(
245  'fieldName' => $this->getName($configuration),
246  'fieldValue' => $configuration->getValue(),
247  'propertyName' => $configuration->getName()
248  );
249  return \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($userFunction, $userFunctionParams, $this, '');
250  }
251 
258  protected function getName(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration) {
259  return 'tx_extensionmanager_tools_extensionmanagerextensionmanager[config][' . $configuration->getName() . '][value]';
260  }
261 
268  protected function renderHiddenFieldForEmptyValue($configuration) {
269  $hiddenFieldNames = array();
270  if ($this->viewHelperVariableContainer->exists('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'renderedHiddenFields')) {
271  $hiddenFieldNames = $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'renderedHiddenFields');
272  }
273  $fieldName = $this->getName($configuration);
274  if (substr($fieldName, -2) === '[]') {
275  $fieldName = substr($fieldName, 0, -2);
276  }
277  if (!in_array($fieldName, $hiddenFieldNames)) {
278  $hiddenFieldNames[] = $fieldName;
279  $this->viewHelperVariableContainer->addOrUpdate('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'renderedHiddenFields', $hiddenFieldNames);
280  return '<input type="hidden" name="' . htmlspecialchars($fieldName) . '" value="0" />';
281  }
282  return '';
283  }
284 
290  public function getDocInstance() {
291  if (!isset($GLOBALS['SOBE']->doc)) {
292  $GLOBALS['SOBE']->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
293  $GLOBALS['SOBE']->doc->backPath = $GLOBALS['BACK_PATH'];
294  }
295  return $GLOBALS['SOBE']->doc;
296  }
297 
298 }
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(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
renderPositiveIntegerField(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)
renderColorPicker(\TYPO3\CMS\Extensionmanager\Domain\Model\ConfigurationItem $configuration)