Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Symfony Forms ChoiceType chained choice_filter #60346

Copy link
Copy link
Open
@RafaelKr

Description

@RafaelKr
Issue body actions

Description

We have a lot of fields which use EnumType. Now some options start to become deprecated. We still need the enum cases to show them for previous form submissions but they shouldn't be select-able for future form submissions anymore. We now solve this by implementing

interface DeprecationAwareInterface
{
    public function isDeprecated(): bool;
}

on our Enum and then use

'choice_filter' => fn (MyEnum $myEnum) => !$myEnum->isDeprecated(),

to filter the available options.

It would be a nice DX improvement if we could handle this on a more global level (ChoiceType TypeExtension). Maybe by making the choice_filter chainable. Then I could add a global filter with high priority to the chain checking for instanceof DeprecationAwareInterface.

We're not using PHP 8.4 yet, but I would like to use the native #[\Deprecated] attribute as soon as we switch to 8.4 which would also nicely come into play for determining the deprecated options.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.