symfony/symfony — pull request #4548 by Burgov (2012-06-10 20:10:01+00:00)
Title: [Form] Make bind() method bind while fields are being added

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #3767
Todo: See Cons

This PR fixes #3767 and could probably replace #3768

The method used in this PR has it's pros and it's cons compared to #3768:

Pro:
- The listeners for both PRE_SET_DATA and PRE_BIND can now be identical, allowing for if's to be removed and possibly prevent code duplication
- No new event is necessary (as opposed to #3768) and other code updates are only minor

Con:
- It is no longer possible to update the view data in the event. Imagine the field 'australian' being removed by the PRE_BIND listener, you'd want to remove 'australian' from the view data in order to prevent a "should not contain extra fields" error. This is the point that'd need work
- It's still possible to trigger an endless loop if one listener adds a field based on a value, and another adds it again. Perhaps a maximum of times the loop is run should be configured for these cases