-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Form] keep labels from configured choices #61928
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
Conversation
xabbuh
commented
Oct 2, 2025
| Q | A |
|---|---|
| Branch? | 6.4 |
| Bug fix? | yes |
| New feature? | no |
| Deprecations? | no |
| Issues | Fix #61927 |
| License | MIT |
|
Works for me :-) One minor note: If just one array element has a key, like this: [
'foo' => MyEnum::Open,
MyEnum::Closed,
]Then the outcome is:
I haven't tried this with |
Page: https://symfony.com/doc/6.4/reference/forms/types/enum.html#choices Feature is added in symfony/symfony#61928 - so you probably want to merge this only when that PR has been released.
|
I've created a docs PR: symfony/symfony-docs#21457 |
|
Thank you @xabbuh. |
|
This seems to break our autocomplete which uses grouping and is setup as follows: 'choices' => [
(string) t('label.paymentmethod.active', [], 'admin.form') => array_filter(
PaymentMethod::cases(),
static fn (PaymentMethod $method): bool => ! \in_array($method, PaymentMethod::internal, true) && ! \in_array($method, PaymentMethod::legacy, true)
),
(string) t('label.paymentmethod.internal', [], 'admin.form') => PaymentMethod::internal, // internal here is an array of enum values
(string) t('label.paymentmethod.legacy', [], 'admin.form') => PaymentMethod::legacy, // same goes for legacy
],Are we doing something obscure or unsupported? It was working fine until this release.. |
|
@alcohol Your use case seems valid to me. I didn't think of the possibility to group choices with the |
| ->setDefault('choice_label', static function (Options $options) { | ||
| if (\is_array($options['choices']) && !array_is_list($options['choices'])) { | ||
| return null; | ||
| } | ||
|
|
||
| return static fn (\UnitEnum $choice) => $choice instanceof TranslatableInterface ? $choice : $choice->name; | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xabbuh That change seems to break BackedEnum implementing TranslatableInterface?
See EasyCorp/EasyAdminBundle#7243