[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Form / ValidationResultsViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * Validation results view helper
21 *
22 * = Examples =
23 *
24 * <code title="Output error messages as a list">
25 * <f:form.validationResults>
26 * <f:if condition="{validationResults.flattenedErrors}">
27 * <ul class="errors">
28 * <f:for each="{validationResults.flattenedErrors}" as="errors" key="propertyPath">
29 * <li>{propertyPath}
30 * <ul>
31 * <f:for each="{errors}" as="error">
32 * <li>{error.code}: {error}</li>
33 * </f:for>
34 * </ul>
35 * </li>
36 * </f:for>
37 * </ul>
38 * </f:if>
39 * </f:form.validationResults>
40 * </code>
41 * <output>
42 * <ul class="errors">
43 * <li>1234567890: Validation errors for argument "newBlog"</li>
44 * </ul>
45 * </output>
46 *
47 * <code title="Output error messages for a single property">
48 * <f:form.validationResults for="someProperty">
49 * <f:if condition="{validationResults.flattenedErrors}">
50 * <ul class="errors">
51 * <f:for each="{validationResults.errors}" as="error">
52 * <li>{error.code}: {error}</li>
53 * </f:for>
54 * </ul>
55 * </f:if>
56 * </f:form.validationResults>
57 * </code>
58 * <output>
59 * <ul class="errors">
60 * <li>1234567890: Some error message</li>
61 * </ul>
62 * </output>
63 *
64 * @api
65 */
66 class ValidationResultsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
67
68 /**
69 * Iterates through selected errors of the request.
70 *
71 * @param string $for 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.
72 * @param string $as The name of the variable to store the current error
73 * @return string Rendered string
74 * @api
75 */
76 public function render($for = '', $as = 'validationResults') {
77 $validationResults = $this->controllerContext->getRequest()->getOriginalRequestMappingResults();
78 if ($validationResults !== NULL && $for !== '') {
79 $validationResults = $validationResults->forProperty($for);
80 }
81 $this->templateVariableContainer->add($as, $validationResults);
82 $output = $this->renderChildren();
83 $this->templateVariableContainer->remove($as);
84 return $output;
85 }
86 }