Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form/Translation] Could not use TranslatableInterface as choice label #46902

Closed
@kadet1090

Description

@kadet1090

Symfony version(s) affected

6.0.8, 6.2 (as of 11.07.2022)

Description

Commit d5ce0e3 introduced TranslatableInterface contract, which could be used for custom translatable objects. As far as I understand this interface should be usable in every place, where TranslatableMessage could be used. This however is not the case, as it cannot be used for example as result from choice_label function.

How to reproduce

Create form with ChoiceType entry, that as choice_label returns some object implementing TranslatableInterface.

Possible Solution

In the Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php:178 we have:

} elseif ($dynamicLabel instanceof TranslatableMessage) {

Which should probably be

} elseif ($dynamicLabel instanceof TranslatableInterface) {

The same thing goes for ChoiceView class.

Additional Context

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