[FOLLOWUP][TASK] EXT:form - change signal slots to hooks
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Hooks / FormElementsOnSubmitHooks.php
1 <?php
2 namespace TYPO3\CMS\Form\Hooks;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Error\Error;
19 use TYPO3\CMS\Extbase\Object\ObjectManager;
20 use TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface;
21 use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
22
23 /**
24 * Scope: frontend
25 * @internal
26 */
27 class FormElementsOnSubmitHooks
28 {
29
30 /**
31 * This hook is invoked by the FormRuntime whenever values are mapped and validated
32 * (after a form page was submitted)
33 *
34 * @param FormRuntime $formRuntime
35 * @param RenderableInterface $renderable
36 * @param mixed $elementValue submitted value of the element *before post processing*
37 * @param array $requestArguments submitted raw request values
38 * @return void
39 * @see FormRuntime::mapAndValidate()
40 * @internal
41 */
42 public function afterSubmit(FormRuntime $formRuntime, RenderableInterface $renderable, $elementValue, array $requestArguments = [])
43 {
44 if ($renderable->getType() === 'AdvancedPassword') {
45 if ($elementValue['password'] !== $elementValue['confirmation']) {
46 $processingRule = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier());
47 $processingRule->getProcessingMessages()->addError(
48 GeneralUtility::makeInstance(ObjectManager::class)
49 ->get(Error::class, 'Password doesn\'t match confirmation', 1334768052)
50 );
51 }
52 $elementValue = $elementValue['password'];
53 }
54
55 return $elementValue;
56 }
57 }