Describe the bug
Up until symfony/form v7.3.4, creating a ChoiceField from a property mapped to a backedEnum implementing TranslatableInterface was working fine, with choices being displayed as the return value from the trans() call on the enum case ; but since symfony/form v7.3.5 it displays the case name instead.
To Reproduce
Steps to reproduce this error and also, the EasyAdmin version used.
EasyAdmin v4.27.3 is affected, if symfony/form is >= v7.3.5 .
Create an entity that has a field mapped to a backedEnum that implements TranslatableInterface, and a crud controller that includes the property in forms as a ChoiceField.
With symfony/form < v7.3.5 in forms, the choices are displayed as the translated value, with symfony/form >= v7.3.5 it is the name that is displayed.
(OPTIONAL) Additional context
I investigated a little, and found the reason why this changed in symfony/form.
When using EnumType (which is used by ChoiceField when enumType is set in the doctrine metadata of the property by default), the label used to (up until v7.3.4) be computed depending on the value of the enum ; if it implemented TranslatableInterface, it was translated, otherwise its name was used.
This was considered a bug, as keys from the choices option should be used as labels, and they changed this behaviour in v7.3.5 to conform to this.
So now, when using EnumType, the labels used are the enum value (correctly translated) only if the keys of the choices array are only integers (well I think they currently test it with array_list, but I saw another PR that changed this to testing if the key was an integer, because it had other side effects).
In the ChoiceConfigurator, the choices are set up with the name of the enum as keys, not with integers, so now they are labelled with that name.
I made the changes to fix this behaviour, with some test that shows the problem, I will make a PR when I have cleaned up everything.
Describe the bug
Up until symfony/form v7.3.4, creating a ChoiceField from a property mapped to a backedEnum implementing TranslatableInterface was working fine, with choices being displayed as the return value from the
trans()call on the enum case ; but since symfony/form v7.3.5 it displays the case name instead.To Reproduce
Steps to reproduce this error and also, the EasyAdmin version used.
EasyAdmin v4.27.3 is affected, if symfony/form is >= v7.3.5 .
Create an entity that has a field mapped to a backedEnum that implements TranslatableInterface, and a crud controller that includes the property in forms as a ChoiceField.
With symfony/form < v7.3.5 in forms, the choices are displayed as the translated value, with symfony/form >= v7.3.5 it is the name that is displayed.
(OPTIONAL) Additional context
I investigated a little, and found the reason why this changed in symfony/form.
When using EnumType (which is used by ChoiceField when
enumTypeis set in the doctrine metadata of the property by default), the label used to (up until v7.3.4) be computed depending on the value of the enum ; if it implemented TranslatableInterface, it was translated, otherwise its name was used.This was considered a bug, as keys from the
choicesoption should be used as labels, and they changed this behaviour in v7.3.5 to conform to this.So now, when using EnumType, the labels used are the enum value (correctly translated) only if the keys of the choices array are only integers (well I think they currently test it with array_list, but I saw another PR that changed this to testing if the key was an integer, because it had other side effects).
In the ChoiceConfigurator, the choices are set up with the name of the enum as keys, not with integers, so now they are labelled with that name.
I made the changes to fix this behaviour, with some test that shows the problem, I will make a PR when I have cleaned up everything.