‪TYPO3CMS  9.5
FormElementHooks.php
Go to the documentation of this file.
1 <?php
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 
24 
30 {
31 
45  public function ‪afterSubmit(‪FormRuntime $formRuntime, ‪RenderableInterface $renderable, $elementValue, array $requestArguments = [])
46  {
47  if ($renderable->‪getType() === 'AdvancedPassword') {
48  if ($elementValue['password'] !== $elementValue['confirmation']) {
49  $processingRule = $renderable->getRootForm()->getProcessingRule($renderable->‪getIdentifier());
50  $processingRule->getProcessingMessages()->addError(
51  GeneralUtility::makeInstance(ObjectManager::class)
52  ->get(
53  Error::class,
54  ‪TranslationService::getInstance()->translate('validation.error.1556283177', null, 'EXT:form/Resources/Private/Language/locallang.xlf'),
55  1556283177
56  )
57  );
58  }
59  $elementValue = $elementValue['password'];
60  }
61 
62  return $elementValue;
63  }
64 
72  public function ‪beforeRendering(‪FormRuntime $formRuntime, ‪RootRenderableInterface $renderable)
73  {
74  if ($renderable->‪getType() === 'Date') {
75  $date = $formRuntime[$renderable->‪getIdentifier()];
76  if ($date instanceof \DateTime) {
77  // @see https://www.w3.org/TR/2011/WD-html-markup-20110405/input.date.html#input.date.attrs.value
78  // 'Y-m-d' = https://tools.ietf.org/html/rfc3339#section-5.6 -> full-date
79  $formRuntime[$renderable->‪getIdentifier()] = $date->format('Y-m-d');
80  }
81  }
82  }
83 
92  public function ‪initializeFormElement(‪RenderableInterface $renderable)
93  {
94  if ($renderable->‪getType() === 'Date' || $renderable->‪getType() === 'DatePicker') {
95  // Set the property mapping type for the `Date` and `DatePicker` element.
96  $renderable->setDataType('DateTime');
97  }
98  }
99 }
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:97
‪TYPO3\CMS\Form\Service\TranslationService\getInstance
‪static TranslationService getInstance()
Definition: TranslationService.php:82
‪TYPO3\CMS\Form\Service\TranslationService
Definition: TranslationService.php:43
‪TYPO3\CMS\Form\Hooks\FormElementHooks
Definition: FormElementHooks.php:30
‪TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface\getIdentifier
‪string getIdentifier()
‪TYPO3\CMS\Form\Hooks\FormElementHooks\initializeFormElement
‪initializeFormElement(RenderableInterface $renderable)
Definition: FormElementHooks.php:92
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface
Definition: RenderableInterface.php:28
‪TYPO3\CMS\Form\Hooks\FormElementHooks\afterSubmit
‪mixed afterSubmit(FormRuntime $formRuntime, RenderableInterface $renderable, $elementValue, array $requestArguments=[])
Definition: FormElementHooks.php:45
‪TYPO3\CMS\Form\Hooks
Definition: DataStructureIdentifierHook.php:3
‪TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface
Definition: RootRenderableInterface.php:27
‪TYPO3\CMS\Extbase\Validation\Error
Definition: Error.php:21
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:3
‪TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface\getType
‪string getType()
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Hooks\FormElementHooks\beforeRendering
‪beforeRendering(FormRuntime $formRuntime, RootRenderableInterface $renderable)
Definition: FormElementHooks.php:72
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25