ObjectChoiceList deprecated

class ObjectChoiceList extends ChoiceList

deprecated

since Symfony 2.7, to be removed in version 3.0. Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.

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) deprecated

Returns the indices corresponding to the given choices.

array getIndicesForValues(array $values) deprecated

Returns the indices corresponding to the given values.

from ChoiceList

Details

__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.

Parameters

array|Traversable $choices The array of choices. Choices may also be given as hierarchy of unlimited depth. Hierarchies are created by creating nested arrays. The title of the sub-hierarchy can be stored in the array key pointing to the nested array. The topmost level of the hierarchy may also be a \Traversable.
string $labelPath A property path pointing to the property used for the choice labels. The value is obtained by calling the getter on the object. If the path is NULL, the object's __toString() method is used instead.
array $preferredChoices A flat array of choices that should be presented to the user with priority.
string $groupPath A property path pointing to the property used to group the choices. Only allowed if the choices are given as flat array.
string $valuePath A property path pointing to the property used for the choice values. If not given, integers are generated instead.
PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.

array getChoices()

Returns the list of choices.

Return Value

array The choices with their indices as keys

array getValues()

Returns the values for the choices.

Return Value

array The values with the corresponding choice indices as keys

array getPreferredViews()

Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys.

Example:

array( 'Group 1' => array( 10 => ChoiceView object, 20 => ChoiceView object, ), 'Group 2' => array( 30 => ChoiceView object, ), )

Return Value

array A nested array containing the views with the corresponding choice indices as keys on the lowest levels and the choice group names in the keys of the higher levels

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:

array( 'Group 1' => array( 10 => ChoiceView object, 20 => ChoiceView object, ), 'Group 2' => array( 30 => ChoiceView object, ), )

Return Value

array A nested array containing the views with the corresponding choice indices as keys on the lowest levels and the choice group names in the keys of the higher levels

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.

Parameters

array $values An array of choice values. Not existing values in this array are ignored

Return Value

array An array of choices with ascending, 0-based numeric keys

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.

Parameters

array $choices An array of choices. Not existing choices in this array are ignored

Return Value

array An array of choice values with ascending, 0-based numeric keys

array getIndicesForChoices(array $choices) deprecated

deprecated

since version 2.4, to be removed in 3.0.

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.

Parameters

array $choices An array of choices. Not existing choices in this array are ignored

Return Value

array An array of indices with ascending, 0-based numeric keys

array getIndicesForValues(array $values) deprecated

deprecated

since version 2.4, to be removed in 3.0.

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.

Parameters

array $values An array of choice values. Not existing values in this array are ignored

Return Value

array An array of indices with ascending, 0-based numeric keys

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/3.3/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.html