‪TYPO3CMS  9.5
TranslateLabelSelectViewHelper.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 
28 {
32  public function ‪initializeArguments()
33  {
34  parent::initializeArguments();
35  $this->registerArgument('optionLabelPrefix', 'string', 'Prefix for locallang lookup');
36  }
37 
46  protected function ‪getOptions()
47  {
48  $options = parent::getOptions();
49  foreach ($options as $value => $label) {
50  $options[$value] = $this->‪translateLabel($label);
51  }
52  return $options;
53  }
54 
61  protected function ‪translateLabel($label)
62  {
63  if ($label === '') {
64  return '';
65  }
66  $labelKey = $this->hasArgument('optionLabelPrefix') ? $this->arguments['optionLabelPrefix'] . $label : $label;
67  $translatedLabel = ‪\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($labelKey, $this->renderingContext->getControllerContext()->getRequest()->getControllerExtensionName());
68  return $translatedLabel ?: $label;
69  }
70 }
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper\translateLabel
‪string translateLabel($label)
Definition: TranslateLabelSelectViewHelper.php:61
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper
Definition: TranslateLabelSelectViewHelper.php:28
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper
Definition: SelectViewHelper.php:91
‪TYPO3\CMS\Belog\ViewHelpers\Form
Definition: TranslateLabelSelectViewHelper.php:2
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper\initializeArguments
‪initializeArguments()
Definition: TranslateLabelSelectViewHelper.php:32
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper\getOptions
‪array getOptions()
Definition: TranslateLabelSelectViewHelper.php:46