symfony/symfony — pull request #3512 by Burgov (2012-03-06 11:03:20+00:00)
Title: made sure the child type default options are passed to the parent when c...

...alling the parent's getParent() method

Bug fix: Yes
Feature addition: No
Backwards compatibility break: Yes (see explanation below)
Symfony2 tests pass: Yes
Fixes the following tickets: -

I ran into the following situation:

I defined a new Form Type, which extends the choice type. Since this new Form Type always needs to be expanded and multiple, I overrode these options in the getDefaultOptionsMethod().

These options were passed into the buildForm method of the choice type just fine, but not into the getParent() method of the choice type.

The result of this was that the parent of the choice type became "field" rather than "form", and even though the checkbox list is rendered fine, and even posts the correct values on submit, the checkbox list is not actually filled before show - all checkboxes are empty. This is because the datamapper on this specific form is not set, since this only happens for types with parent 'form'.

This PR makes sure the default options of the child type are passed to the getParent() method of the parent type.

Unfortunately this poses a small BC break, where a form type now can no longer rely on the options of it's parents within the getDefaultOptions method. This posed a problem in DoctrineType, which is fixed in this PR as well.

Also, the getDefaultOptions is called twice as often now, once top-down and once bottom-up. The first one making sure that child options are passed into the getParent method of the parents and the second one to build the definite list of options

I'd be happy to hear any other possible solutions. At first I thought this bug affected 2.0 as well, but that appeared not to be true.