‪TYPO3CMS  11.5
TranslateLabelSelectViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
32 {
36  public function ‪initializeArguments()
37  {
38  parent::initializeArguments();
39  $this->registerArgument('optionLabelPrefix', 'string', 'Prefix for locallang lookup');
40  }
41 
50  protected function ‪getOptions()
51  {
52  $options = parent::getOptions();
53  foreach ($options as $value => $label) {
54  $options[$value] = $this->‪translateLabel($label);
55  }
56  return $options;
57  }
58 
65  protected function ‪translateLabel($label)
66  {
67  if ($label === '') {
68  return '';
69  }
70  $labelKey = $this->hasArgument('optionLabelPrefix') ? $this->arguments['optionLabelPrefix'] . $label : $label;
71  $translatedLabel = ‪LocalizationUtility::translate($labelKey, $this->renderingContext->getRequest()->getControllerExtensionName());
72  return $translatedLabel ?: $label;
73  }
74 }
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper\translateLabel
‪string translateLabel($label)
Definition: TranslateLabelSelectViewHelper.php:65
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper
Definition: TranslateLabelSelectViewHelper.php:32
‪TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper
Definition: SelectViewHelper.php:95
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Belog\ViewHelpers\Form
Definition: TranslateLabelSelectViewHelper.php:16
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper\initializeArguments
‪initializeArguments()
Definition: TranslateLabelSelectViewHelper.php:36
‪TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper\getOptions
‪array getOptions()
Definition: TranslateLabelSelectViewHelper.php:50