src/Form/ChoiceList/ModelChoiceList.php
protected function load($choices)
    {
        if (\is_array($choices) && \count($choices) > 0) {
            $entities = $choices;
        } elseif ($this->query) {
            $entities = $this->modelManager->executeQuery($this->query);
        } else {
            $entities = $this->modelManager->findBy($this->class);
        }

        if (null === $entities) {
            return [];
        }

        $choices = [];
        $this->entities = [];

        foreach ($entities as $key => $entity) {
            if ($this->propertyPath) {
                // If the property option was given, use it
                $value = $this->propertyAccessor->getValue($entity, $this->propertyPath);
            } else {
                // Otherwise expect a __toString() method in the entity
                try {
                    $value = (string) $entity;
                } catch (\Exception $e) {
                    throw new RuntimeException(sprintf('Unable to convert the entity "%s" to string, provide '
                        .'"property" option or implement "__toString()" method in your entity.', ClassUtils::getClass($entity)), 0, $e);
                }
            }

            if (\count($this->identifier) > 1) {
                // When the identifier consists of multiple field, use
                // naturally ordered keys to refer to the choices
                $choices[$key] = $value;
                $this->entities[$key] = $entity;
            } else {
                // When the identifier is a single field, index choices by
                // entity ID for performance reasons
                $id = current($this->getIdentifierValues($entity));
                $choices[$id] = $value;
                $this->entities[$id] = $entity;
            }
        }

        return $choices;
    }
protected function load($choices)
    {
        if (\is_array($choices) && \count($choices) > 0) {
            $entities = $choices;
        } elseif ($this->query) {
            $entities = $this->modelManager->executeQuery($this->query);
        } else {
            $entities = $this->modelManager->findBy($this->class);
        }

        if (null === $entities) {
            return [];
        }

        $choices = [];
        $this->entities = [];

        foreach ($entities as $key => $entity) {
            if ($this->propertyPath) {
                // If the property option was given, use it
                $value = $this->propertyAccessor->getValue($entity, $this->propertyPath);
            } else {
                // Otherwise expect a __toString() method in the entity
                try {
                    $value = (string) $entity;
                } catch (\Exception $e) {
                    throw new RuntimeException(sprintf('Unable to convert the entity "%s" to string, provide '
                        .'"property" option or implement "__toString()" method in your entity.', ClassUtils::getClass($entity)), 0, $e);
                }
            }

            if (\count($this->identifier) > 1) {
                // When the identifier consists of multiple field, use
                // naturally ordered keys to refer to the choices
                $choices[$key] = $value;
                $this->entities[$key] = $entity;
            } else {
                // When the identifier is a single field, index choices by
                // entity ID for performance reasons
                $id = current($this->getIdentifierValues($entity));
                $choices[$id] = $value;
                $this->entities[$id] = $entity;
            }
        }

        return $choices;
    }
protected function load ( $ choices ) { if ( \ is_array ( $ choices ) && \ count ( $ choices ) > 0 ) { $ entities = $ choices ; } elseif ( $ this -> query ) { $ entities = $ this -> modelManager -> executeQuery ( $ this -> query ) ; } else { $ entities = $ this -> modelManager -> findBy ( $ this -> class ) ; } if ( null === $ entities ) { return [ ] ; } $ choices = [ ] ; $ this -> entities = [ ] ; foreach ( $ entities as $ key => $ entity ) { if ( $ this -> propertyPath ) { // If the property option was given, use it $ value = $ this -> propertyAccessor -> getValue ( $ entity , $ this -> propertyPath ) ; } else { // Otherwise expect a __toString() method in the entity try { $ value = ( string ) $ entity ; } catch ( \ Exception $ e ) { throw new RuntimeException ( sprintf ( 'Unable to convert the entity "%s" to string, provide ' . '"property" option or implement "__toString()" method in your entity.' , ClassUtils :: getClass ( $ entity ) ) , 0 , $ e ) ; } } if ( \ count ( $ this -> identifier ) > 1 ) { // When the identifier consists of multiple field, use // naturally ordered keys to refer to the choices $ choices [ $ key ] = $ value ; $ this -> entities [ $ key ] = $ entity ; } else { // When the identifier is a single field, index choices by // entity ID for performance reasons $ id = current ( $ this -> getIdentifierValues ( $ entity ) ) ; $ choices [ $ id ] = $ value ; $ this -> entities [ $ id ] = $ entity ; } } return $ choices ; }
Initializes the choices and returns them.

The choices are generated from the entities. If the entities have a
composite identifier, the choices are indexed using ascending integers.
Otherwise the identifiers are used as indices.

If the entities were passed in the "choices" option, this method
does not have any significant overhead. Otherwise, if a query builder
was passed in the "query" option, this builder is now used to construct
a query which is executed. In the last case, all entities for the
underlying class are fetched from the repository.

If the option "property" was passed, the property path in that option
is used as option values. Otherwise this method tries to convert
objects to strings using __toString().

@return array An array of choices
Initializes the choices and returns them .