Description
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