~xaav/tsep/symfony

Viewing all changes in revision 7646.

  • Committer: Fabien Potencier
  • Date: 2015-05-20 08:29:08 UTC
  • mfrom: (7616.1.1)
  • Revision ID: git-v1:e9ecd0e00b833b0856b01ebcba7b05de1fc948fa
bug #14551 [2.7][Form] Fixed ChoiceType with legacy ChoiceList (xelaris)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7][Form] Fixed ChoiceType with legacy ChoiceList

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14382
| License       | MIT
| Doc PR        |

The "Backwards compatibility" condition doesn't grap (e.g. when passing a `SimpleChoiceList` as `choice_list` on `ChoiceType`), as the default value for the `ChoiceType` option `preferred_choices` is `array()` instead of `null`. So I changed the condition from `null === $preferredChoices` to `empty($preferredChoices)`.
Then there was an issue with accessing `attr` in `form_div_layout.html.twig`, since the deprecated `Symfony\Component\Form\Extension\Core\View\ChoiceView` doesn't provide an `attr` attribute. Since the docblocks of `Symfony\Component\Form\ChoiceList\View\ChoiceListView` state `$choices` and `$preferredChoices` to be instances of `Symfony\Component\Form\ChoiceList\View\ChoiceView` instead of `Symfony\Component\Form\Extension\Core\View\ChoiceView` I fixed the template issue by mapping the deprecated `ChoiceView` objects to the new one with an empty `attr`.

@webmozart Could you have a look at it, please?

Without this PR the following example would render numeric values as labels:
```php
        $formBuilder->add('choices', 'choice', array(
            'choice_list' => new SimpleChoiceList(array(
                'creditcard' => 'Credit card payment',
                'cash' => 'Cash payment'
            ))
        ));
```

Commits
-------

a98e484 [Form] Fix ChoiceType with legacy ChoiceList

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: