🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@xabbuh
Copy link
Member

@xabbuh xabbuh commented Oct 2, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #61927
License MIT

@ThomasLandauer
Copy link
Contributor

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:

  • foo
  • 0

I haven't tried this with ChoiceType, and I guess it's the intended behavior anyway - so that's fine for me :-)

ThomasLandauer added a commit to ThomasLandauer/symfony-docs that referenced this pull request Oct 2, 2025
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.
@ThomasLandauer
Copy link
Contributor

ThomasLandauer commented Oct 2, 2025

I've created a docs PR: symfony/symfony-docs#21457

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit 4221e02 into symfony:6.4 Oct 3, 2025
9 of 11 checks passed
@xabbuh xabbuh deleted the issue-61927 branch October 3, 2025 12:11
This was referenced Oct 28, 2025
@alcohol
Copy link
Contributor

alcohol commented Oct 30, 2025

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..

@xabbuh
Copy link
Member Author

xabbuh commented Oct 30, 2025

@alcohol Your use case seems valid to me. I didn't think of the possibility to group choices with the choices option. Can you open a new issue please so this regression doesn't get lost?

Comment on lines +33 to +39
->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;
})
Copy link
Contributor

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

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.

8 participants