symfony/symfony — Issue #2516: formtypes dont fire *set_data events when used in collection
Author: kmohrf
Created: 2011-10-29 22:14:42+00:00
State: open

Even though i don’t really know if this is a bug or a misuse of the collection type by me i add this as an issue:

I have an OrganisationType and a PersonType. As the organisation has a lot of persons associated the OrganisationType includes a collection with the type PersonType.

What i wanted to do is set the PersonTypes forms label to a value of the underlying object. The problem is, that this object is never passed to the arguments part of the buildForm function. Adding formevents like pre_set_data or set_data aren`t working too. they’re just never called.

when i started to look around in the collectiontype i noticed the added eventsubscriber of class [1]. in line 92 this class iterates over the passed data as part of a pre_set_data event. what it never does is passing the value of the data (in this case an object of my class Person) to the collections type. i actually merges some default options with array_replace but not the data itself. when i add a "data" => $value to this array_replace function my PersonType suddenly works without any problems.

so i guess the "data" => $value part is missing as part of the array_replace function and i therefor report it as a bug.

feel free to let me know that I’m totally wrong ;)

[1] Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener