[BUGFIX] EXT:form - catch exceptions within page module and form engine
[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 * @see FormRuntime::mapAndValidate()
39 * @internal
40 */
41 public function afterSubmit(FormRuntime $formRuntime, RenderableInterface $renderable, $elementValue, array $requestArguments = [])
42 {
43 if ($renderable->getType() === 'AdvancedPassword') {
44 if ($elementValue['password'] !== $elementValue['confirmation']) {
45 $processingRule = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier());
46 $processingRule->getProcessingMessages()->addError(
47 GeneralUtility::makeInstance(ObjectManager::class)
48 ->get(Error::class, 'Password doesn\'t match confirmation', 1334768052)
49 );
50 }
51 $elementValue = $elementValue['password'];
52 }
53
54 return $elementValue;
55 }
56 }