10000 Merge branch '4.4' into 5.3 · symfony/symfony-docs@271465a · GitHub
[go: up one dir, main page]

Skip to content

Commit 271465a

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: Minor tweak Inserted a warning about a limitation model transformers
2 parents 037a7dc + ab51509 commit 271465a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

form/data_transformers.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,20 @@ Which transformer you need depends on your situation.
478478

479479
To use the view transformer, call ``addViewTransformer()``.
480480

481+
.. caution::
482+
483+
Be careful with model transformers and
484+
:doc:`Collection </reference/forms/types/collection>` field types.
485+
Collection's children are created early at ``PRE_SET_DATA`` by its
486+
``ResizeFormListener`` and their data is populated later from the normalized
487+
data. So your model transformer cannot reduce the number of items within the
488+
Collection (i.e. filtering out some items), as in that case the collection
489+
ends up with some empty children.
490+
491+
A possible workaround for that limitation could be not using the underlying
492+
object directly, but a DTO (Data Transfer Object) instead, that implements
493+
the transformation of such incompatible data structures.
494+
481495
So why Use the Model Transformer?
482496
---------------------------------
483497

0 commit comments

Comments
 (0)
0