Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

mhlavac
Copy link

@mhlavac mhlavac commented Oct 14, 2015

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?

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?
@stof
Copy link
Member

stof commented Oct 14, 2015

yes, it is a supported use case (it is even the main API, as property path are transformed into a callable internally)

@mhlavac
Copy link
Author

mhlavac commented Oct 14, 2015

Ok, is the example ok, or should I also add index in function args so it's clear to everyone?

@stof
Copy link
Member

stof commented Oct 14, 2015

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 string|callable.

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.

@mhlavac
Copy link
Author

mhlavac commented Oct 14, 2015

@stof thank you. I've updated it, if they accept it then I'll squash the commits into one.

@javiereguiluz
Copy link
Member

@mhlavac there is no need to squash the commits because symfony and symfony-docs repos are managed with a tool that does the squashing automatically.

$builder->add('gender', 'entity', array(
'class' => 'MyBundle:Gender',
'choice_label' => function(MyBundle\Entity\Gender $gender, $index) {
return $index . '. ' . $gender->getLocalizedGender($this->locale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indention correct here?

@xabbuh
Copy link
Member

xabbuh commented Oct 18, 2015

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?

@HeahDude
Copy link
Contributor

Should be closed as fixed by #5876

@xabbuh xabbuh closed this Jan 30, 2016
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.

6 participants