diff --git a/Documentation/ApiOverview/Events/Events/Form/BeforeRenderableIsValidatedEvent.rst b/Documentation/ApiOverview/Events/Events/Form/BeforeRenderableIsValidatedEvent.rst new file mode 100644 index 0000000000..31d14f789c --- /dev/null +++ b/Documentation/ApiOverview/Events/Events/Form/BeforeRenderableIsValidatedEvent.rst @@ -0,0 +1,33 @@ +.. include:: /Includes.rst.txt +.. index:: Events; BeforeRenderableIsValidatedEvent + +.. _BeforeRenderableIsValidatedEvent: + +================================== +BeforeRenderableIsValidatedEvent +================================== + +.. versionadded:: 14.0 + The event :php-short:`TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent` + is a replacement for the removed hook + :php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterSubmit']`. + +The event :php-short:`TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent` +is dispatched just before a renderable is validated. This event allows a renderable +to add custom logic before it is validated. + + +.. _BeforeRenderableIsValidatedEvent-example: + +Example +======= + +.. literalinclude:: _BeforeRenderableIsValidatedEvent/_MyEventListener.php + :caption: EXT:my_extension/Classes/EventListener/MyEventListener.php + +.. _BeforeRenderableIsValidatedEvent-api: + +API +=== + +.. include:: /CodeSnippets/Events/Form/BeforeRenderableIsValidatedEvent.rst.txt diff --git a/Documentation/ApiOverview/Events/Events/Form/_BeforeRenderableIsValidatedEvent/_MyEventListener.php b/Documentation/ApiOverview/Events/Events/Form/_BeforeRenderableIsValidatedEvent/_MyEventListener.php new file mode 100644 index 0000000000..764d1fd58b --- /dev/null +++ b/Documentation/ApiOverview/Events/Events/Form/_BeforeRenderableIsValidatedEvent/_MyEventListener.php @@ -0,0 +1,35 @@ +renderable; + if ($renderable->getType() !== 'AdvancedPassword') { + return; + } + + $elementValue = $event->value; + if ($elementValue['password'] !== $elementValue['confirmation']) { + $processingRule = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier()); + $processingRule->getProcessingMessages()->addError( + GeneralUtility::makeInstance( + Error::class, + GeneralUtility::makeInstance(TranslationService::class)->translate('validation.error.1556283177', null, 'EXT:form/Resources/Private/Language/locallang.xlf'), + 1556283177, + ), + ); + } + $event->value = $elementValue['password']; + } +} diff --git a/Documentation/CodeSnippets/Config/Api/Events/EventsForm.php b/Documentation/CodeSnippets/Config/Api/Events/EventsForm.php index 69d4bba285..8dc0bce757 100644 --- a/Documentation/CodeSnippets/Config/Api/Events/EventsForm.php +++ b/Documentation/CodeSnippets/Config/Api/Events/EventsForm.php @@ -37,6 +37,12 @@ 'targetFileName' => 'CodeSnippets/Events/Form/BeforeRenderableIsRemovedFromFormEvent.rst.txt', 'withCode' => false, ], + [ + 'action' => 'createPhpClassDocs', + 'class' => \TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent::class, + 'targetFileName' => 'CodeSnippets/Events/Form/BeforeRenderableIsRemovedFromFormEvent.rst.txt', + 'withCode' => false, + ], [ 'action' => 'createPhpClassDocs', 'class' => \TYPO3\CMS\Form\Event\BeforeFormIsDuplicatedEvent::class, diff --git a/Documentation/CodeSnippets/Events/Form/BeforeRenderableIsValidatedEvent.rst.txt b/Documentation/CodeSnippets/Events/Form/BeforeRenderableIsValidatedEvent.rst.txt new file mode 100644 index 0000000000..17fed6ac9f --- /dev/null +++ b/Documentation/CodeSnippets/Events/Form/BeforeRenderableIsValidatedEvent.rst.txt @@ -0,0 +1,18 @@ +.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets +.. php:namespace:: TYPO3\CMS\Form\Event + +.. php:class:: BeforeRenderableIsValidatedEvent + + Listeners to this event can add custom validation logic. + + .. php:attr:: renderable + :public: + + .. php:attr:: formRuntime + :public: + + .. php:attr:: value + :public: + + .. php:attr:: request + :public: