Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Accept a closure as label formatter in an ObjectChoiceList #10261

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 1 commit into from

Conversation

iamluc
Copy link
Contributor

@iamluc iamluc commented Feb 14, 2014

Sometimes, the __toString() method is not enough to format the labels of a choices list because you want to show differents labels on differents FormType, or because you need externals informations.

This commit adds support to closure to fix this.

ie.

<?php
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $localizator = new Localizator();

        $builder
            ->add('name')
            ->add('country', 'entity', array(
                'class' => 'MyProject\Bundle\DemoBundle\Entity\Country',
                'property' => function ($country) use ($localizator) {
                    return $country->getName().' ('.$localizator->translate($country->getName()).')';
                }
                )
            )
        ;
    }
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

@@ -173,7 +182,12 @@ private function extractLabels($choices, array &$labels)
$labels[$i] = array();
$this->extractLabels($choice, $labels[$i]);
} elseif ($this->labelPath) {
$labels[$i] = $this->propertyAccessor->getValue($choice, $this->labelPath);
if ($this->labelPath instanceof \Closure) {
$test = $this->labelPath;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be removed =)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oups... Fixed. Thanks

@mvrhov
Copy link

mvrhov commented Feb 14, 2014

See #3479

@iamluc
Copy link
Contributor Author

iamluc commented Feb 14, 2014

Sorry, I searched before pushing but did not find your PR...
Should I close this one ?

@fabpot
Copy link
Member

fabpot commented Feb 19, 2014

Closing in favor of #4067

@fabpot fabpot closed this Feb 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.