Core\ChoiceList\ObjectChoiceList (Component\Form\Extension)
Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList
class ObjectChoiceList extends ChoiceList
A choice list for object choices.
Supports generation of choice labels, choice groups and choice values by calling getters of the object (or associated objects).
$choices = array($user1, $user2);
// call getName() to determine the choice labels $choiceList = new ObjectChoiceList($choices, 'name');
Methods
__construct(array|Traversable $choices, string $labelPath = null, array $preferredChoices = array(), string $groupPath = null, string $valuePath = null, PropertyAccessorInterface $propertyAccessor = null) Creates a new object choice list. | ||
array | getChoices() Returns the list of choices. | from ChoiceList |
array | getValues() Returns the values for the choices. | from ChoiceList |
array | getPreferredViews() Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys. | from ChoiceList |
array | getRemainingViews() Returns the choice views of the choices that are not preferred as nested array with the choice groups as top-level keys. | from ChoiceList |
array | getChoicesForValues(array $values) Returns the choices corresponding to the given values. | from ChoiceList |
array | getValuesForChoices(array $choices) Returns the values corresponding to the given choices. | |
array | getIndicesForChoices(array $choices) Returns the indices corresponding to the given choices. | |
array | getIndicesForValues(array $values) Returns the indices corresponding to the given values. | from ChoiceList |
Details
public __construct(array|Traversable $choices, string $labelPath = null, array $preferredChoices = array(), string $groupPath = null, string $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
Creates a new object choice list.
public array getChoices()
Returns the list of choices.
public array getValues()
Returns the values for the choices.
public array getPreferredViews()
Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys.
Example:
public array getRemainingViews()
Returns the choice views of the choices that are not preferred as nested array with the choice groups as top-level keys.
Example:
public array getChoicesForValues(array $values)
Returns the choices corresponding to the given values.
The choices can have any data type.
The choices must be returned with the same keys and in the same order as the corresponding values in the given array.
public array getValuesForChoices(array $choices)
Returns the values corresponding to the given choices.
The values must be strings.
The values must be returned with the same keys and in the same order as the corresponding choices in the given array.
public array getIndicesForChoices(array $choices)
Returns the indices corresponding to the given choices.
The indices must be positive integers or strings accepted by {@link \Symfony\Component\Form\FormConfigBuilder::validateName()}.
The index "placeholder" is internally reserved.
The indices must be returned with the same keys and in the same order as the corresponding choices in the given array.
public array getIndicesForValues(array $values)
Returns the indices corresponding to the given values.
The indices must be positive integers or strings accepted by {@link \Symfony\Component\Form\FormConfigBuilder::validateName()}.
The index "placeholder" is internally reserved.
The indices must be returned with the same keys and in the same order as the corresponding values in the given array.
© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/3.0/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.html