W3cubDocs

/Symfony 4.1

DoctrineChoiceLoader

class DoctrineChoiceLoader implements ChoiceLoaderInterface

Loads choices using a Doctrine object manager.

Methods

__construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)

Creates a new choice loader.

ChoiceListInterface loadChoiceList(callable|null $value = null)

Loads a list of choices.

string[] loadValuesForChoices(array $choices, callable|null $value = null)

Loads the values corresponding to the given choices.

array loadChoicesForValues(array $values, callable|null $value = null)

Loads the choices corresponding to the given values.

Details

__construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)

Creates a new choice loader.

Optionally, an implementation of {@link EntityLoaderInterface} can be passed which optimizes the object loading for one of the Doctrine mapper implementations.

Parameters

ObjectManager $manager The object manager
string $class The class name of the loaded objects
IdReader $idReader The reader for the object IDs
EntityLoaderInterface $objectLoader The objects loader

ChoiceListInterface loadChoiceList(callable|null $value = null)

Loads a list of choices.

Optionally, a callable can be passed for generating the choice values. The callable receives the choice as first and the array key as the second argument.

Parameters

callable|null $value The callable which generates the values from choices

Return Value

ChoiceListInterface The loaded choice list

string[] loadValuesForChoices(array $choices, callable|null $value = null)

Loads the values corresponding to the given choices.

The values are returned with the same keys and in the same order as the corresponding choices in the given array.

Optionally, a callable can be passed for generating the choice values. The callable receives the choice as first and the array key as the second argument.

Parameters

array $choices An array of choices. Non-existing choices in this array are ignored
callable|null $value The callable generating the choice values

Return Value

string[] An array of choice values

array loadChoicesForValues(array $values, callable|null $value = null)

Loads the choices corresponding to the given values.

The choices are returned with the same keys and in the same order as the corresponding values in the given array.

Optionally, a callable can be passed for generating the choice values. The callable receives the choice as first and the array key as the second argument.

Parameters

array $values An array of choice values. Non-existing values in this array are ignored
callable|null $value The callable generating the choice values

Return Value

array An array of choices

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.html