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

Skip to content

[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

Conversation

alexandre-daubois
Copy link
Member

It leads to loss of information because it'll use __toString to cast, which is incompatible with newly added TranslatableMessage, for example.

Q A
Branch? 5.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #40622
License MIT
Doc PR none

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:

* @param string|false $label The label displayed to humans; pass false to discard the label

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.

Copy link
Member

@yceruto yceruto left a 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.

@yceruto
Copy link
Member

yceruto commented Apr 10, 2021

* @param string|false $label The label displayed to humans; pass false to discard the label

and yes, I would update the docblock to add TranslatableMessage too.

@alexandre-daubois alexandre-daubois force-pushed the fix-use-translatable-message-choice-label branch from 0b8df2b to c13a56d Compare April 11, 2021 18:06
@alexandre-daubois alexandre-daubois changed the title [Form] Don't directly cast objects to string from choice_label callable result [Form] Add missing TranslatableMessage support to choice_label option of ChoiceType Apr 11, 2021
@alexandre-daubois
Copy link
Member Author

Thank you so much @yceruto for your advice. I updated the code thanks to your suggestions and edited the PR title as well.

@nicolas-grekas nicolas-grekas force-pushed the fix-use-translatable-message-choice-label branch from c13a56d to c2873aa Compare May 7, 2021 14:01
Copy link
Member

@nicolas-grekas nicolas-grekas left a 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)

@nicolas-grekas
Copy link
Member

Thank you @alexandre-daubois.

@nicolas-grekas nicolas-grekas merged commit ffbf8c2 into symfony:5.2 May 7, 2021
This was referenced May 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants