8000 [Form] Choice types with choice_list option breaks on 2.7 · Issue #14382 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Form] Choice types with choice_list option breaks on 2.7 #14382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
soullivaneuh opened this issue Apr 17, 2015 · 4 comments
Closed

[Form] Choice types with choice_list option breaks on 2.7 #14382

soullivaneuh opened this issue Apr 17, 2015 · 4 comments

Comments

@soullivaneuh
Copy link
Contributor

Form choice type with choice_list option seems to be broken on rendering since Symfony 2.7.

See the concerned ticket: sonata-project/SonataAdminBundle#2916

And the concerned type: https://github.com/sonata-project/SonataAdminBundle/blob/master/Form/Type/ModelType.php#L103-L115

Can you confirm?

@soullivaneuh soullivaneuh changed the title Choice types with choice_list option break on 2.7 Choice types with choice_list option breaks on 2.7 Apr 17, 2015
@soullivaneuh soullivaneuh changed the title Choice types with choice_list option breaks on 2.7 [Form] Choice types with choice_list option breaks on 2.7 Apr 17, 2015
@HeahDude
Copy link
Contributor

`@deprecated since version 2.7, to be removed in 3.0.

  •         Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.`
    

change the extended class
in https://github.com/sonata-project/SonataAdminBundle/blob/master/Form/ChoiceList/ModelChoiceList.php

@soullivaneuh
Copy link
Contributor Author
8000 soullivaneuh commented Apr 19, 2015

@HeahDude Thanks for this indication but deprecated does not mean BC break.

Upgrade from 2.6 to 2.7 should not break any bundle. Normally, no code modification had to be done, isn't it?

@soullivaneuh
Copy link
Contributor Author

BTW, using ArrayChoiceList instead of SimpleChoiceList does not resolve this issue. Nothing changed.

fabpot added a commit that referenced this issue May 20, 2015
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
@fabpot fabpot closed this as completed May 20, 2015
@soullivaneuh
Copy link
Contributor Author
soullivaneuh commented Jul 24, 2015 6CB6

@fabpot @xelaris Having again exactly the same issue since upgrading from 2.7.1 to 2.7.2.

Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0