Skip to content

[Form] Choice type int values (BC Fix) #21957

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
wants to merge 2 commits into from

Conversation

mcfedr
Copy link
Contributor

@mcfedr mcfedr commented Mar 10, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21952
License MIT

#21267 unnecessarily forced all choice values to be strings, this was a BC braking change.

Everything can work fine if they are strings or ints. specifically the issue was because array_flip is used on the choices array, but this function will work fine with ints as well as strings.

Normally, when using HTML forms all data comes as strings, but the symfony/form component has use cases beyond this, specifically, I use it with JSON data, where valid values for a ChoiceType might not be strings.

@mcfedr mcfedr force-pushed the choice-type-int-values branch from 4953631 to be1c3a8 Compare March 10, 2017 08:51
@mcfedr mcfedr changed the title Choice type int values Choice type int values (BC Fix) Mar 10, 2017
@@ -171,7 +171,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}

foreach ($data as $v) {
if (null !== $v && !is_string($v)) {
if (null !== $v && !is_string($v) && !is_int($v)) {
throw new TransformationFailedException('All choices submitted must be NULL or strings.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message should be updated too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it.

@mcfedr mcfedr force-pushed the choice-type-int-values branch from be1c3a8 to 56e3974 Compare March 10, 2017 09:37
@nicolas-grekas nicolas-grekas modified the milestones: 2.8, 2.7 Mar 10, 2017
@mcfedr mcfedr force-pushed the choice-type-int-values branch from 56e3974 to dad87f8 Compare March 10, 2017 09:50
@mcfedr mcfedr changed the title Choice type int values (BC Fix) [Form] Choice type int values (BC Fix) Mar 10, 2017
@fabpot
Copy link
Member

fabpot commented Mar 10, 2017

Thank you @mcfedr.

fabpot added a commit that referenced this pull request Mar 10, 2017
This PR was squashed before being merged into the 2.7 branch (closes #21957).

Discussion
----------

[Form] Choice type int values (BC Fix)

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21952
| License       | MIT

#21267 unnecessarily forced all choice values to be strings, this was a BC braking change.

Everything can work fine if they are strings or ints. specifically the issue was because `array_flip` is used on the `choices` array, but this function will work fine with ints as well as strings.

Normally, when using HTML forms all data comes as strings, but the `symfony/form` component has use cases beyond this, specifically, I use it with JSON data, where valid values for a `ChoiceType` might not be strings.

Commits
-------

ed211e9 [Form] Choice type int values (BC Fix)
@fabpot fabpot closed this Mar 10, 2017
@mcfedr mcfedr deleted the choice-type-int-values branch March 11, 2017 20:55
@mcfedr
Copy link
Contributor Author

mcfedr commented Mar 11, 2017

Thank you @fabpot for Symfony :)

@mcfedr
Copy link
Contributor Author

mcfedr commented Mar 12, 2017

This needs to land it 2.8 and 3.2 branches as well.

@fabpot
Copy link
Member

fabpot commented Mar 12, 2017

Merged into 2.8 as well. For 3.2, I will let @nicolas-grekas do the merge

chihiro-adachi pushed a commit to chihiro-adachi/ec-cube that referenced this pull request Mar 14, 2017
- symfony 3.2.5/6で、choice typeでint値を受け付けなくなっていたため(symfony/symfony#21267)
- 21267はbc break扱いで再度修正が入っている(symfony/symfony#21957)
- symfony3.2.7で解消されると思われるが、テスト通したいので直しておく
@superhaggis
Copy link

Ping @nicolas-grekas - any ETA on the 3.2 merge? We're still locked to 3.2.4 here as a result of the issue. 😢

@fabpot
Copy link
Member

fabpot commented Mar 29, 2017

@superhaggis It's been merged a while ago.

@fabpot
Copy link
Member

fabpot commented Mar 29, 2017

Or are you asking for a new release? In that case, that should be done very soon.

@superhaggis
Copy link

@fabpot Yeah, I guess I'm asking for a new release. Thanks for the update. 😄

@fabpot fabpot mentioned this pull request Apr 4, 2017
@PhilippSchreiber
Copy link

When will this fix be released in 3.2.*? Downgrading right now to 3.2.4 :(

@fabpot
Copy link
Member

fabpot commented Apr 4, 2017

A new 3.2 version will probably be released today.

@fabpot fabpot mentioned this pull request Apr 5, 2017
chihiro-adachi pushed a commit to chihiro-adachi/ec-cube that referenced this pull request Apr 5, 2017
…y/symfony#21267) - 21267はbc break扱いで再度修正が入っている(symfony/symfony#21957) - symfony3.2.7で解消されると思われるが、テスト通したいので直しておく
@fabpot fabpot mentioned this pull request Apr 5, 2017
fabpot added a commit that referenced this pull request May 9, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Minor: Fix comment in ChoiceType

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | n/a
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Forgotten to be updated in: #21957

Commits
-------

a49d79c [Form] Minor: Fix comment in ChoiceType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants