Inheritance: extends Sulu\Component\Rest\ApiWrapper
Example #1
0
 /**
  * prepare an api entity.
  *
  * @param CollectionEntity   $entity
  * @param string             $locale
  * @param CollectionEntity[] $entities           nested set
  * @param array              $breadcrumbEntities
  *
  * @return Collection
  */
 protected function getApiEntity(CollectionInterface $entity, $locale, $entities = null, $breadcrumbEntities = null)
 {
     $apiEntity = new Collection($entity, $locale);
     $children = [];
     if ($entities !== null) {
         foreach ($entities as $possibleChild) {
             if (($parent = $possibleChild->getParent()) !== null && $parent->getId() === $entity->getId()) {
                 $children[] = $this->getApiEntity($possibleChild, $locale, $entities);
             }
         }
     }
     $apiEntity->setChildren($children);
     if ($entity->getParent() !== null) {
         $apiEntity->setParent($this->getApiEntity($entity->getParent(), $locale));
     }
     if ($breadcrumbEntities !== null) {
         $breadcrumbApiEntities = [];
         foreach ($breadcrumbEntities as $entity) {
             $breadcrumbApiEntities[] = $this->getApiEntity($entity, $locale);
         }
         $apiEntity->setBreadcrumb($breadcrumbApiEntities);
     }
     return $this->addPreview($apiEntity);
 }
Example #2
0
 /**
  * @param Collection $parent
  *
  * @return $this
  */
 public function setParent($parent)
 {
     if ($parent !== null) {
         $this->entity->setParent($parent->getEntity());
     } else {
         $this->entity->setParent(null);
     }
     // FIXME remove cache for parent and generate it on the fly
     //       reason: preview images cannot be generated without a service
     $this->parent = $parent;
     return $this;
 }