Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[2.7] [Form] Bug : choice_value is neither ignored nor validated when not null in EntityType #17693

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
HeahDude opened this issue Feb 4, 2016 · 0 comments

Comments

@HeahDude
Copy link
Contributor

HeahDude commented Feb 4, 2016

Since #14050 ChoiceType has a choice_value option to dynamically set the option value as a callable or a PropertyPath.

EntityType since inherited this option but its implementation defines a value based on the database id by default.

While choice_label replaces the deprecated property option and choice_attr is working well with EntityType, here's an example in a recent question on stack overflow :
http://stackoverflow.com/questions/35085983/access-properties-and-methods-of-a-class-while-configuring-entitytype-in-formbui/35097053#35097053

(As a matter of fact choice_attr and choice_value are not mentioned in the doc of EntityType as of 2.7 but I will very soon open an issue in symfony-docs for it and other suggestions)

That said, the real point of this issue is that nothing prevents to use choice_value with EntityType when its actual implementation seems to enforce using id as value.

But defining choice_value is actually working and renders the form view as expected.

The problem is it cannot be validated since submitting the customised choice value will not match any id in the transformation process and an error is mapped to the field saying "This value is not valid".

Two ways to solve it IMO :

1/ Define choice_value as unavailable in EntityType both in the doc (2.7) and in the class by a normalizer :

// Symfony\Bridge\Doctrine\Form\Type\EntityType::configureOptions()
// ...
$choiceValueNormalizer = function (Options $options) {
    return null;
};

$resolver->setNormalizer('choice_value', $choiceValueNormalizer);
// ...

But that would make me sad so let's talk about :

2/ Let developers use choice_value in EntityType as it's very close to work like in ChoiceType, and of courses, update the doc.

For this, there's only need to check if choice_value is null in DoctrineChoiceLoader.

PR on its way !

HeahDude added a commit to HeahDude/symfony that referenced this issue Feb 5, 2016
HeahDude added a commit to HeahDude/symfony that referenced this issue Feb 11, 2016
fabpot added a commit that referenced this issue Feb 15, 2016
…pe (HeahDude)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7] [DoctrineBridge] [Form] fix choice_value in EntityType

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17693, #17271, #13964
| License       | MIT
| Doc PR        | symfony/symfony-docs#6260

Commits
-------

2336d5c fix choice_value option in EntityType and add some tests
@fabpot fabpot closed this as completed Feb 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants