public function getBranchesOfType($type, $lang = null)
 {
     $class = $this->contentTypeService->getContentTypeClass($type);
     if (null === $class) {
         throw new \InvalidArgumentException("Can’t find page class name for {$type}");
     }
     return $this->nodeVersions->getBranchesOfType($class, $lang);
 }
 public function generate(HasNodeInterface $page, $absolute = false, array $parameters = [])
 {
     $nodeVersion = $this->nodeVersions->getNodeVersionFor($page);
     if (null === $nodeVersion) {
         throw new \InvalidArgumentException('This Page has no Node associated with it!');
     }
     $nodeTranslation = $nodeVersion->getNodeTranslation();
     return $this->generator->generate("_slug", ["url" => $nodeTranslation->getUrl(), "_locale" => $nodeTranslation->getLang()] + $parameters, $absolute ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH);
 }
 private function getValueId($value)
 {
     if ($value instanceof Category) {
         return $this->nodeVersions->getNodeRef($value->getNodeId());
     } elseif ($value instanceof Result || is_array($value) && isset($value['node_version_id'])) {
         $id = is_array($value) ? $value['node_version_id'] : $value->__get('node_version_id');
         return $this->nodeVersions->getRef($id);
     }
     return null;
 }
 /**
  * @param HasNodeInterface|Node|null $parent
  * @param array                      $options
  *
  * @return Branch
  */
 public function getChildren($parent = null, array $options = [])
 {
     if ($parent instanceof HasNodeInterface) {
         $node = $this->publicNodeVersions->getNodeFor($parent);
     } elseif ($parent instanceof Category) {
         $node = $this->nodeRepository->find($parent->getNodeId());
     } elseif ($parent instanceof Node) {
         $node = $parent;
     } else {
         $node = null;
     }
     return $this->getNodeChildren(['parent' => $node] + $options);
 }
 /**
  * @param mixed $value
  * @return int
  */
 public function resolve($value)
 {
     if (is_int($value) || is_string($value)) {
         return (int) $value;
     }
     if ($value instanceof Category) {
         return $value->getNodeId();
     }
     if ($value instanceof Result) {
         return $value->get('node_id');
     }
     if ($value instanceof Node) {
         return $value->getId();
     }
     if ($value instanceof NodeTranslation) {
         return $value->getNode()->getId();
     }
     if ($value instanceof HasNodeInterface) {
         return $this->nodeVersions->getNodeFor($value)->getId();
     }
     throw new \InvalidArgumentException();
 }
 /**
  * @param HasNodeInterface $page
  * @param bool             $full
  *
  * @invalidate cache on structure change
  * @return Category[]
  */
 public function getBreadcrumbs(HasNodeInterface $page, $full = false)
 {
     $key = sprintf('%s:%d:%d', ClassLookup::getClass($page), $page->getId(), $full);
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     $nodeTranslation = $this->nodeVersions->getNodeTranslationFor($page);
     if (null === $nodeTranslation) {
         throw new \RuntimeException(sprintf('Cant find node for %s:%d page', get_class($page), $page->getId()));
     }
     $lang = $nodeTranslation->getLang();
     $breadcrumbs = $this->breadCrumbsService->getNodePath($nodeTranslation->getNode());
     $parents = (new ArrayCollection($breadcrumbs))->filter(function (Node $node) use($full) {
         return $full || false === $node->isHiddenFromNav();
     })->map(function (Node $node) use($lang) {
         return $node->getNodeTranslation($lang, true);
     })->map(function (NodeTranslation $nt) {
         return $this->nodeTranslationToCategory($nt);
     })->toArray();
     $this->cache->save($key, $parents);
     return $parents;
 }