TYPO3 CMS  TYPO3_8-7
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 
25 
33 {
35 
41  public function initializeArguments()
42  {
43  parent::initializeArguments();
44  $this->registerArgument('element', RootRenderableInterface::class, 'Form Element to translate', true);
45  $this->registerArgument('error', Error::class, '', false, '');
46  $this->registerArgument('code', 'integer', 'Error code - deprecated', false);
47  $this->registerArgument('arguments', 'array', 'Error arguments - deprecated', false, null);
48  $this->registerArgument('defaultValue', 'string', 'The default value - deprecated', false, '');
49  }
50 
60  public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
61  {
62  $element = $arguments['element'];
63  $error = $arguments['error'];
64 
65  $code = $arguments['code'];
66  $errorArguments = $arguments['arguments'];
67  $defaultValue = $arguments['defaultValue'];
68 
69  if ($error instanceof Error) {
70  $code = $error->getCode();
71  $errorArguments = $error->getArguments();
72  $defaultValue = $error->__toString();
73  }
74 
76  $formRuntime = $renderingContext
77  ->getViewHelperVariableContainer()
78  ->get(RenderRenderableViewHelper::class, 'formRuntime');
79 
80  return TranslationService::getInstance()->translateFormElementError(
81  $element,
82  $code,
83  $errorArguments,
84  $defaultValue,
85  $formRuntime
86  );
87  }
88 }