Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList::loadEntities PHP Метод

loadEntities() приватный Метод

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 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().
private loadEntities ( $entities, $group = null )
    private function loadEntities($entities, $group = null)
    {
        foreach ($entities as $key => $entity) {
            if (is_array($entity)) {
                // Entities are in named groups
                $this->loadEntities($entity, $key);
                continue;
            }

            if ($this->propertyPath) {
                // If the property option was given, use it
                $value = $this->propertyPath->getValue($entity);
            } else {
                // Otherwise expect a __toString() method in the entity
                $value = (string)$entity;
            }

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

            if (null === $group) {
                // Flat list of choices
                $this->choices[$id] = $value;
            } else {
                // Nested choices
                $this->choices[$group][$id] = $value;
            }

            $this->entities[$id] = $entity;
        }
    }