symfony/symfony — pull request #3479 by mvrhov (2012-03-01 10:15:16+00:00)
Title: [WIP] Entity choice label builder callback

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: phpdoc, test

This adds label_builder option as a callback to the EntityChoiceList class.

Right now __toString method is used to get the labels for a choices. Usually this is ok, but sometimes you need to have different labels depending on where the choice filed is displayed, or __toString is else where for different purposes.

Usage example:

```php
$builder
->add('account', 'entity', array(
'class' => 'xxx\Entity\Account',
'label_builder' => function ($entity) {
/** @var $entity xxx\Entity\Account */
$ret = '';
$ret .= $entity->getFirstName() . ' ';
$ret .= $entity->getLastName() . ' ';

$ret .= $entity->getCompany() ? ' @ ' . $entity->getCompany() : '';

return $ret;

},
))
```
Right now I just want to see if this would be considered a good idea, before I continue working on this.