/** * {@inheritdoc} */ public function getTreeById($id, $locale) { $collectionSet = $this->collectionRepository->findTree($id, $locale); /** @var Collection[] $collections sorted by id */ $collections = []; /** @var Collection[] $result collections without parent */ $result = []; foreach ($collectionSet as $collection) { $apiEntity = new Collection($collection, $locale); $this->addPreview($apiEntity); $collections[$collection->getId()] = $apiEntity; if ($collection->getParent() !== null) { $collections[$collection->getParent()->getId()]->addChild($apiEntity); } else { $result[] = $apiEntity; } } return $result; }