Skip to content
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

Fix ChoiceField when entity is enumType and no choices were given #5944

Merged
merged 3 commits into from
Oct 22, 2023

Conversation

Uplink03
Copy link
Contributor

@Uplink03 Uplink03 commented Oct 2, 2023

Fix ChoiceField when entity is enumType and no choices were given explicitly

Bugs

BUG: if setChoices is not called on the ChoiceField, and the backing entity field is an Enum, the dropdown displays 0, 1, 2, 3, etc., because the $choices array ends up like this:

array:2 [
  0 => App\Enum\ProjectTypeEnum {
    +name: "PHP"
    +value: "php"
  }
  1 => App\Enum\ProjectTypeEnum {
    +name: "DOCKER"
    +value: "docker"
  }
]

BUG: Symfony Forms attempts to convert the enum to string.

Fixes

Fix the ChoiceConfigurator

This PR fixes the ChoiceConfigurator to behave as if ->setChoices(MyEnum::cases()) were called.

Related to commit 65a422b of PR #5879 by @SerheyDolgushev

Fix the forms

Although closed, bug #5641 was not addressed by PR #5879. Without the change suggested by the original reported, the following errors are thrown:

The EDIT action of a CRUD that contains a ChoiceField with an enum:

Object of class App\Enum\ProjectTypeEnum could not be converted to string

The Create action of a CRUD that contains a ChoiceField with an enum (the NEW page doesn't complain until submitted):

Expected argument of type "App\Enum\ProjectTypeEnum", "string" given at property path "type".

@Uplink03 Uplink03 marked this pull request as ready for review October 2, 2023 22:38
@javiereguiluz javiereguiluz added this to the 4.x milestone Oct 22, 2023
@javiereguiluz
Copy link
Collaborator

@Uplink03 thanks for this bug fix. I'm sorry I managed the handling of enums in choice fields so badly 😐

@javiereguiluz javiereguiluz merged commit c30a8a0 into EasyCorp:4.x Oct 22, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants