‪TYPO3CMS  9.5
TranslateElementErrorViewHelper.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25 
31 class ‪TranslateElementErrorViewHelper extends AbstractViewHelper
32 {
33  use CompileWithRenderStatic;
34 
40  public function ‪initializeArguments()
41  {
42  $this->registerArgument('element', RootRenderableInterface::class, 'Form Element to translate', true);
43  $this->registerArgument('error', Error::class, '', false, '');
44  $this->registerArgument('code', 'integer', 'Error code - deprecated', false, '');
45  $this->registerArgument('arguments', 'array', 'Error arguments - deprecated', false, null);
46  $this->registerArgument('defaultValue', 'string', 'The default value - deprecated', false, '');
47  }
48 
57  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
58  {
59  $element = $arguments['element'];
60  $error = $arguments['error'];
61 
62  $code = $arguments['code'];
63  $errorArguments = $arguments['arguments'];
64  $defaultValue = $arguments['defaultValue'];
65 
66  if ($error instanceof ‪Error) {
67  $code = $error->getCode();
68  $errorArguments = $error->getArguments();
69  $defaultValue = $error->__toString();
70  } else {
71  trigger_error(
72  'TranslateElementErrorViewHelper arguments "code", "arguments" and "defaultValue" will be removed in TYPO3 v10.0. Use "error" instead.',
73  E_USER_DEPRECATED
74  );
75  }
76 
78  $formRuntime = $renderingContext
79  ->getViewHelperVariableContainer()
80  ->get(RenderRenderableViewHelper::class, 'formRuntime');
81 
83  $element,
84  $code,
85  $errorArguments,
86  $defaultValue,
87  $formRuntime
88  );
89  }
90 }
‪TYPO3\CMS\Form\Service\TranslationService\getInstance
‪static TranslationService getInstance()
Definition: TranslationService.php:82
‪TYPO3\CMS\Form\Service\TranslationService
Definition: TranslationService.php:43
‪TYPO3\CMS\Form\ViewHelpers\TranslateElementErrorViewHelper
Definition: TranslateElementErrorViewHelper.php:32
‪TYPO3\CMS\Form\Service\TranslationService\translateFormElementError
‪string translateFormElementError(RootRenderableInterface $element, int $code, array $arguments, string $defaultValue='', FormRuntime $formRuntime)
Definition: TranslationService.php:466
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:22
‪TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface
Definition: RootRenderableInterface.php:27
‪TYPO3\CMS\Form\ViewHelpers\TranslateElementErrorViewHelper\initializeArguments
‪initializeArguments()
Definition: TranslateElementErrorViewHelper.php:39
‪TYPO3\CMS\Form\ViewHelpers
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:3
‪TYPO3\CMS\Form\ViewHelpers\TranslateElementErrorViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: TranslateElementErrorViewHelper.php:56