‪TYPO3CMS  ‪main
ValidationResultsViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\Variables\ScopedVariableProvider;
24 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
27 
76 final class ‪ValidationResultsViewHelper extends AbstractViewHelper
77 {
78  use CompileWithRenderStatic;
79 
85  protected ‪$escapeOutput = false;
86 
87  public function ‪initializeArguments(): void
88  {
89  $this->registerArgument('for', 'string', 'The name of the error name (e.g. argument name or property name). This can also be a property path (like blog.title), and will then only display the validation errors of that property.', false, '');
90  $this->registerArgument('as', 'string', 'The name of the variable to store the current error', false, 'validationResults');
91  }
92 
96  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
97  {
98  $for = $arguments['for'];
99  $as = $arguments['as'];
100 
103  $extbaseRequestParameters = $renderingContext->getRequest()->getAttribute('extbase');
104  $validationResults = $extbaseRequestParameters->getOriginalRequestMappingResults();
105  if ($validationResults !== null && $for !== '') {
106  $validationResults = $validationResults->forProperty($for);
107  }
108 
109  $variableProvider = new ScopedVariableProvider($renderingContext->getVariableProvider(), new StandardVariableProvider([$as => $validationResults]));
110  $renderingContext->setVariableProvider($variableProvider);
111 
112  ‪$output = $renderChildrenClosure();
113 
114  $renderingContext->setVariableProvider($variableProvider->getGlobalVariableProvider());
115 
116  return ‪$output;
117  }
118 }
‪TYPO3\CMS\Fluid\ViewHelpers\Form
Definition: AbstractFormFieldViewHelper.php:18
‪TYPO3\CMS\Fluid\ViewHelpers\Form\ValidationResultsViewHelper\renderStatic
‪static mixed renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: ValidationResultsViewHelper.php:94
‪TYPO3\CMS\Fluid\ViewHelpers\Form\ValidationResultsViewHelper
Definition: ValidationResultsViewHelper.php:77
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Fluid\ViewHelpers\Form\ValidationResultsViewHelper\initializeArguments
‪initializeArguments()
Definition: ValidationResultsViewHelper.php:85
‪TYPO3\CMS\Fluid\ViewHelpers\Form\ValidationResultsViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: ValidationResultsViewHelper.php:83
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters
Definition: ExtbaseRequestParameters.php:35
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:35