src/Sulu/Bundle/MediaBundle/Collection/Manager/CollectionManager.php
protected function getApiEntity(CollectionInterface $entity, $locale, $entities = null, $breadcrumbEntities = null)
    {
        $apiEntity = new Collection($entity, $locale);

        $children = null;

        if (null !== $entities) {
            $children = [];
            foreach ($entities as $possibleChild) {
                if (null !== ($parent = $possibleChild->getParent()) && $parent->getId() === $entity->getId()) {
                    $children[] = $this->getApiEntity($possibleChild, $locale, $entities);
                }
            }
        }

        $apiEntity->setChildren($children);
        if (null !== $entity->getParent()) {
            $apiEntity->setParent($this->getApiEntity($entity->getParent(), $locale));
        }

        if (null !== $breadcrumbEntities) {
            $this->setBreadcrumbToCollection($apiEntity, $locale, $breadcrumbEntities);
        }

        if ($entity && $entity->getId()) {
            $apiEntity->setMediaCount($this->collectionRepository->countMedia($entity));
            $apiEntity->setSubCollectionCount($this->collectionRepository->countSubCollections($entity));
        }

        return $this->addPreview($apiEntity);
    }
protected function getApiEntity(CollectionInterface $entity, $locale, $entities = null, $breadcrumbEntities = null)
    {
        $apiEntity = new Collection($entity, $locale);

        $children = null;

        if (null !== $entities) {
            $children = [];
            foreach ($entities as $possibleChild) {
                if (null !== ($parent = $possibleChild->getParent()) && $parent->getId() === $entity->getId()) {
                    $children[] = $this->getApiEntity($possibleChild, $locale, $entities);
                }
            }
        }

        $apiEntity->setChildren($children);
        if (null !== $entity->getParent()) {
            $apiEntity->setParent($this->getApiEntity($entity->getParent(), $locale));
        }

        if (null !== $breadcrumbEntities) {
            $this->setBreadcrumbToCollection($apiEntity, $locale, $breadcrumbEntities);
        }

        if ($entity && $entity->getId()) {
            $apiEntity->setMediaCount($this->collectionRepository->countMedia($entity));
            $apiEntity->setSubCollectionCount($this->collectionRepository->countSubCollections($entity));
        }

        return $this->addPreview($apiEntity);
    }
protected function getApiEntity ( CollectionInterface $ entity , $ locale , $ entities = null , $ breadcrumbEntities = null ) { $ apiEntity = new Collection ( $ entity , $ locale ) ; $ children = null ; if ( null !== $ entities ) { $ children = [ ] ; foreach ( $ entities as $ possibleChild ) { if ( null !== ( $ parent = $ possibleChild -> getParent ( ) ) && $ parent -> getId ( ) === $ entity -> getId ( ) ) { $ children [ ] = $ this -> getApiEntity ( $ possibleChild , $ locale , $ entities ) ; } } } $ apiEntity -> setChildren ( $ children ) ; if ( null !== $ entity -> getParent ( ) ) { $ apiEntity -> setParent ( $ this -> getApiEntity ( $ entity -> getParent ( ) , $ locale ) ) ; } if ( null !== $ breadcrumbEntities ) { $ this -> setBreadcrumbToCollection ( $ apiEntity , $ locale , $ breadcrumbEntities ) ; } if ( $ entity && $ entity -> getId ( ) ) { $ apiEntity -> setMediaCount ( $ this -> collectionRepository -> countMedia ( $ entity ) ) ; $ apiEntity -> setSubCollectionCount ( $ this -> collectionRepository -> countSubCollections ( $ entity ) ) ; } return $ this -> addPreview ( $ apiEntity ) ; }
Prepare an api entity.

@param CollectionInterface $entity
@param string $locale
@param CollectionEntity[] $entities nested set
@param array $breadcrumbEntities

@return Collection
Prepare an api entity .