Description
Hi @bschussek
I'm having an issue since I've updated my code to Symfony v2.3.1, I have an embed form defined as virtual and neither FormEvents::PRE_SET_DATA
event nor setData
method are called anymore.
I wrote a test to be more explicit on the problem I have: https://gist.github.com/jeremyb/5764427. I ran this test on the Symfony 2.2 and 2.3 branches and I think there's a regression on testVirtualAndEvents
.
Test | 2.2 | 2.3 |
---|---|---|
testVirtual | success | success |
testVirtualWithCountry | fails | fails |
testVirtualAndEvents | success | fails |
I'm trying to understand the differences made on Form component between 2.2 and 2.3 and I see some PR that can be related to this issue:
- I would have thought that PR [2.3] [Form] Renamed option "virtual" to "inherit_data" and improved handling of such forms #6573 fixes the
setData
call for virtual forms but it seems that it's not the case and the latest comment of @Strate confirms that ; - the PR [Form] *_SET_DATA events are now guaranteed to be fired *after* the initial children were added #7878 introduces the
auto_initialize
option, so thesetData
isn't called anymore on children if I understand it correctly?
So I think my problem comes from the fact that setData
isn't called for virtual forms and because auto_initialize
prevents initialization of children (according to this the exception Automatic initialization is only supported on root forms.
), so without initialization and data the FormEvents::PRE_SET_DATA
event isn't called anymore. Is this correct?
I'm not sure whether it's a bug or an evolution of the Form component but is there a new way to do this kind of code and adapt the behavior of a virtual form from the data?
Let me know if you want me to commit my FormVirtualTest.php
test somewhere, I can do a PR to your symfony fork if you want.