Skip to content

Commit 9e9ca5b

Browse files
committed
minor #15780 [Form] Inserted a warning about a limitation of model transformers (spackmat)
This PR was submitted for the 5.3 branch but it was merged into the 4.4 branch instead. Discussion ---------- [Form] Inserted a warning about a limitation of model transformers There is a surprising limitation of model transformers, that cannot filter out items for a Collection field type. Took me a whole day to find out, so here is a warning about that. See symfony/symfony#36469 for details. (Maybe that issue should be linked for further details?). Commits ------- 0feac63 Inserted a warning about a limitation model transformers
2 parents 7ba3c7b + 0feac63 commit 9e9ca5b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

form/data_transformers.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ Which transformer you need depends on your situation.
482482

483483
To use the view transformer, call ``addViewTransformer()``.
484484

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

0 commit comments

Comments
 (0)