Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #54315 [Serializer] Fixed BackedEnumNormalizer priority for trans…
…latable enum (IndraGunawan) This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Serializer] Fixed BackedEnumNormalizer priority for translatable enum | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT ```php enum MyEnum: string implements TranslatableInterface { case Get = 'GET'; case Post = 'POST'; case Update = 'UPDATE'; public function trans(TranslatorInterface $translator, ?string $locale = null): string { return match ($this) { self::Get => 'custom_get', self::Post => 'custom_post', self::Update => 'custom_update' }; } } ``` ```php class MyController { public function __invoke(SerializerInterface $serializer) { dd($serializer->serialize(MyEnum::Get)); // ""custom_get"" , Expected result: ""GET"" } } ``` serialize a BackedEnum that implements `TranslatableInterface` will return the translation value instead of the enum item value. this is because `TranslatableNormalizer` ([ref](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php#L116-L118)) has higher priority than `BackedEnumNormalizer` this PR changes the `BackedEnumNormalizer` priority higher than `TranslatableNormalizer` priority Commits ------- 42fde94 [Serializer] Fixed BackedEnumNormalizer priority for translatable enum
- Loading branch information