[TASK] Update examples in ValidationResults ViewHelper
[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 script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 /**
25 * Validation results view helper
26 *
27 * = Examples =
28 *
29 * <code title="Output error messages as a list">
30 * <f:form.validationResults>
31 * <f:if condition="{validationResults.flattenedErrors}">
32 * <ul class="errors">
33 * <f:for each="{validationResults.flattenedErrors}" as="errors" key="propertyPath">
34 * <li>{propertyPath}
35 * <ul>
36 * <f:for each="{errors}" as="error">
37 * <li>{error.code}: {error}</li>
38 * </f:for>
39 * </ul>
40 * </li>
41 * </f:for>
42 * </ul>
43 * </f:if>
44 * </f:form.validationResults>
45 * </code>
46 * <output>
47 * <ul class="errors">
48 * <li>1234567890: Validation errors for argument "newBlog"</li>
49 * </ul>
50 * </output>
51 *
52 * <code title="Output error messages for a single property">
53 * <f:form.validationResults for="someProperty">
54 * <f:if condition="{validationResults.flattenedErrors}">
55 * <ul class="errors">
56 * <f:for each="{validationResults.errors}" as="error">
57 * <li>{error.code}: {error}</li>
58 * </f:for>
59 * </ul>
60 * </f:if>
61 * </f:form.validationResults>
62 * </code>
63 * <output>
64 * <ul class="errors">
65 * <li>1234567890: Some error message</li>
66 * </ul>
67 * </output>
68 *
69 * @api
70 */
71 class ValidationResultsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
72
73 /**
74 * Iterates through selected errors of the request.
75 *
76 * @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.
77 * @param string $as The name of the variable to store the current error
78 * @return string Rendered string
79 * @api
80 */
81 public function render($for = '', $as = 'validationResults') {
82 $validationResults = $this->controllerContext->getRequest()->getOriginalRequestMappingResults();
83 if ($for !== '') {
84 $validationResults = $validationResults->forProperty($for);
85 }
86 $this->templateVariableContainer->add($as, $validationResults);
87 $output = $this->renderChildren();
88 $this->templateVariableContainer->remove($as);
89 return $output;
90 }
91 }
92
93 ?>