Skip to content

Commit 897d4cf

Browse files
[FEATURE] Add PSR-14 Event after form is built (#6286)
Resolves: TYPO3-Documentation/Changelog-To-Doc#1394 Releases: main
1 parent 65314b4 commit 897d4cf

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. include:: /Includes.rst.txt
2+
.. index:: Events; AfterFormIsBuiltEvent
3+
4+
.. _AfterFormIsBuiltEvent:
5+
6+
=====================
7+
AfterFormIsBuiltEvent
8+
=====================
9+
10+
.. versionadded:: 14.0
11+
The events :php-short:`TYPO3\CMS\Form\Event\AfterFormIsBuiltEvent`
12+
and :php-short:`TYPO3\CMS\Form\Event\BeforeRenderableIsAddedToFormEvent`
13+
provide an improved replacement for the removed hook
14+
:php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterBuildingFinished']`.
15+
16+
The event :php-short:`TYPO3\CMS\Form\Event\AfterFormIsBuiltEvent`
17+
allows the form definition to be modified after a form has been created.
18+
19+
20+
.. _AfterFormIsBuiltEvent-example:
21+
22+
Example
23+
=======
24+
25+
.. literalinclude:: _AfterFormIsBuiltEvent/_MyEventListener.php
26+
:caption: EXT:my_extension/Classes/EventListener/MyEventListener.php
27+
28+
.. _AfterFormIsBuiltEvent-api:
29+
30+
API
31+
===
32+
33+
.. include:: /CodeSnippets/Events/Form/AfterFormIsBuiltEvent.rst.txt
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MyVendor\MyExtension\EventListener;
6+
7+
use TYPO3\CMS\Core\Attribute\AsEventListener;
8+
use TYPO3\CMS\Form\Event\AfterFormIsBuiltEvent;
9+
10+
final readonly class MyEventListener
11+
{
12+
#[AsEventListener(
13+
identifier: 'my-extension/after-form-is-built',
14+
)]
15+
public function __invoke(AfterFormIsBuiltEvent $event): void
16+
{
17+
$event->form->setLabel('foo');
18+
}
19+
}

Documentation/CodeSnippets/Config/Api/Events/EventsForm.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

33
return [
4+
[
5+
'action' => 'createPhpClassDocs',
6+
'class' => \TYPO3\CMS\Form\Event\AfterFormIsBuiltEvent::class,
7+
'targetFileName' => 'CodeSnippets/Events/Form/AfterFormIsBuiltEvent.rst.txt',
8+
'withCode' => false,
9+
],
410
[
511
'action' => 'createPhpClassDocs',
612
'class' => \TYPO3\CMS\Form\Mvc\Persistence\Event\AfterFormDefinitionLoadedEvent::class,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
2+
.. php:namespace:: TYPO3\CMS\Form\Event
3+
4+
.. php:class:: AfterFormIsBuiltEvent
5+
6+
Listeners to this event will be able to modify the form definition
7+
after a form is created.
8+
9+
.. php:attr:: form
10+
:public:

0 commit comments

Comments
 (0)