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

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kadet1090 opened this issue Jul 11, 2022 · 0 comments · Fixed by #46946
Closed

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

kadet1090 opened this issue Jul 11, 2022 · 0 comments · Fixed by #46946

Comments

@kadet1090
Copy link

kadet1090 commented Jul 11, 2022

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

@kadet1090 kadet1090 added the Bug label Jul 11, 2022
@xabbuh xabbuh added the Form label Jul 11, 2022
@OskarStark OskarStark changed the title [Form/Translation] Could not use TranslatableInterface as choice label [Form/Translation] Could not use TranslatableInterface as choice label Jul 14, 2022
@fabpot fabpot closed this as completed Jul 20, 2022
fabpot added a commit that referenced this issue Jul 20, 2022
…erface (alamirault)

This PR was merged into the 6.2 branch.

Discussion
----------

[Form] ChoiceType choices must support TranslatableInterface

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #46902
| License       | MIT
| Doc PR        |

Before this PR only `TranslatableMessage` was supported in ChoiceView/ChoiceType choices labels.

Now `TranslatableInterface` contract is supported.

Commits
-------

cffb4df [Form] ChoiceView label allow TranslatableInterface, not only TranslatableMessage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants