8000 minor #18587 [Form] Fix form data related events definition (HeahDude) · symfony/symfony-docs@cf269d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf269d6

Browse files
committed
minor #18587 [Form] Fix form data related events definition (HeahDude)
This PR was merged into the 5.4 branch. Discussion ---------- [Form] Fix form data related events definition The `PRE_SET_DATA` event is not safe to modify a form based on the data since the data can still be changed by listeners. `POST_SET_DATA` should be used instead. Commits ------- f041d70 [Form] Fix form data related events definition
2 parents 21f2d8f + f041d70 commit cf269d6

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

form/events.rst

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ A) The ``FormEvents::PRE_SET_DATA`` Event
4848
.........................................
4949

5050
The ``FormEvents::PRE_SET_DATA`` event is dispatched at the beginning of the
51-
``Form::setData()`` method. It can be used to:
52-
53-
* Modify the data given during pre-population;
54-
* Modify a form depending on the pre-populated data (adding or removing fields dynamically).
51+
``Form::setData()`` method. It is used to modify the data given during
52+
pre-population with
53+
:method:`FormEvent::setData() <Symfony\\Component\\Form\\FormEvent::setData>`.
54+
The method :method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
55+
is locked since the event is dispatched from it and will throw an exception
56+
if called from a listener.
5557

5658
=============== ========
5759
Data Type Value
@@ -66,13 +68,6 @@ View data ``null``
6668
See all form events at a glance in the
6769
:ref:`Form Events Information Table <component-form-event-table>`.
6870

69-
.. caution::
70-
71-
During ``FormEvents::PRE_SET_DATA``,
72-
:method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
73-
is locked and will throw an exception if used. If you wish to modify
74-
data, you should use
75-
:method:`FormEvent::setData() <Symfony\\Component\\Form\\FormEvent::setData>`
7671
instead.
7772

7873
.. sidebar:: ``FormEvents::PRE_SET_DATA`` in the Form component
@@ -88,8 +83,8 @@ B) The ``FormEvents::POST_SET_DATA`` Event
8883

8984
The ``FormEvents::POST_SET_DATA`` event is dispatched at the end of the
9085
:method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
91-
method. This event is mostly here for reading data after having pre-populated
92-
the form.
86+
method. This event can be used to modify a form depending on the populated data
87+
(adding or removing fields dynamically).
9388

9489
=============== ====================================================
9590
Data Type Value

0 commit comments

Comments
 (0)
0