-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add missing TranslatableMessage support to choice_label option of ChoiceType #40759
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
[Form] Add missing TranslatableMessage support to choice_label option of ChoiceType #40759
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a specific check against TranslatableMessage wouldn't a problem from my point of view and it would be better than allowing non-stringable objects from here.
src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php
Outdated
Show resolved
Hide resolved
and yes, I would update the docblock to add TranslatableMessage too. |
0b8df2b
to
c13a56d
Compare
Thank you so much @yceruto for your advice. I updated the code thanks to your suggestions and edited the PR title as well. |
c13a56d
to
c2873aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I fixed deps=low tests by skipping the test case there)
Thank you @alexandre-daubois. |
It leads to loss of information because it'll use
__toString
to cast, which is incompatible with newly addedTranslatableMessage
, for example.So this one's a bit tricky in my mind. I didn't want to check if
$dynamicLabel instanceof TranslatableMessage
, because of course it doesn't belong to the same component.Aside, it would sound so strange to me to add
|object
to$label
here:symfony/src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php
Line 40 in bb1e1e5
But maybe that's the way to go? Requiring your help here. I'm fully open to your ideas, as we're loosing a big feature here by losing
TranslatableMessage
translation parameters.If the passed object doesn't implement
__toString
, it'll lead to an exception during template rendering, as expected.