-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add note about using choice_label as a callback #5788
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
I was wondering how to call a method with an argument for some time and then I've came with an idea of using ArrayAccess that can be used with PropertyAccessor. Then I found I can actually use callback in `choice_label`, but this was not documented. Is this correct usage?
yes, it is a supported use case (it is even the main API, as property path are transformed into a callable internally) |
Ok, is the example ok, or should I also add index in function args so it's clear to everyone? |
IMO, you need to document the arguments received by the callable (even though most cases will only need the first one). You should also change the type of the option, to say And I'm not sure this should be a note actually. It should be documented at the same level of importance than the property path usage IMO. But I will let the doc team make the choice here. |
@stof thank you. I've updated it, if they accept it then I'll squash the commits into one. |
@mhlavac there is no need to squash the commits because |
$builder->add('gender', 'entity', array( | ||
'class' => 'MyBundle:Gender', | ||
'choice_label' => function(MyBundle\Entity\Gender $gender, $index) { | ||
return $index . '. ' . $gender->getLocalizedGender($this->locale); |
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.
indention correct here?
First, thank you very much for your contribution @mhlavac. Unfortunately, someone already opened a similar PR (see #5755). Also we have a lot more possibilities to configure the label path and most of this also applies to some other options (see my comment in #5755 (comment)). Maybe you and @aivus would like to work together on this? |
Should be closed as fixed by #5876 |
I was wondering how to call a method with an argument for some time and then I've came with an idea of using ArrayAccess that can be used with PropertyAccessor.
Then I found I can actually use callback in
choice_label
, but this was not documented. Is this correct usage?