/** * Generate unique route pattern. * * @param NodeInterface $node * @param RouteInterface $route * * @return string * * @throws RouteException */ private function generateUniqueRoutePattern(NodeInterface $node, RouteInterface $route) { if (false === $this->routerHelper->hasController($node->getType())) { throw new RouteException('Cannot generate route pattern!'); } if (!trim($route->getRoutePattern())) { throw new RouteException('Route pattern cannot be empty!'); } return $this->getUniqueRoutePattern($route); }
/** * Reverse transform. * * @param NodeTranslationInterface $nodeTranslation * * @return NodeTranslationInterface */ public function reverseTransform($nodeTranslation) { $route = $nodeTranslation->getRoute(); if (null !== $route && $route->getRoutePattern()) { $node = $nodeTranslation->getNode(); if ($this->routerHelper->hasController($node->getType())) { $this->routeGenerator->generateRoute($route, $node, $nodeTranslation->getLang()); $this->routeManager->add($route); } else { $this->routeManager->remove($route); } } return $nodeTranslation; }
/** * Check if node parent is online. * * @param NodeInterface $node * @param string $locale * * @return bool */ private function parentIsOnline(NodeInterface $node, $locale) { $parent = $node->getParent(); if (null !== $parent && $this->routeHelper->hasController($parent->getType())) { if (false === $this->routeHelper->hasRoute($locale, $node)) { return false; } if (null === ($translation = $parent->getTranslation($locale))) { return false; } if (null === ($route = $translation->getRoute())) { return false; } return $route->isVisible(); } return true; }
/** * On sitemap node edit. * * @param SitemapNodeEvent $event */ public function onSitemapNodeEdit(SitemapNodeEvent $event) { $node = $event->getNode(); $menuTab = $this->tabFactory->createMenuTab($node); $event->addTab($menuTab); if (null === $node->getParent()) { return; } if (RedirectRoute::NODE_TYPE === $node->getType()) { $redirectRouteTab = $this->tabFactory->createRedirectRouteTab($node); $event->addTab($redirectRouteTab); } elseif ($this->routerHelper->hasController($node->getType())) { $routeTab = $this->tabFactory->createRouteTab($node); $event->addTab($routeTab); $seoTab = $this->tabFactory->createSeoTab($node); $event->addTab($seoTab); } }
/** * On create sitemap node. * * @param NodeInterface $node */ public function onCreateNode(NodeInterface $node) { if ($this->routerHelper->hasController($node->getType())) { foreach ($node->getTranslations() as $translation) { $route = $this->routeFactory->create($translation); $seoMetadata = $this->seoFactory->create($translation); $translation->setRoute($route); $translation->setSeoMetadata($seoMetadata); } } if (null !== $this->priorityStrategy) { $this->priorityStrategyRegistry->get($this->priorityStrategy)->increase($node); } }
/** * Render toolbar template. * * @param NodeInterface $node * * @return string */ private function renderToolbar(NodeInterface $node) { return $this->responseHelper->render('TadckaSitemapBundle:Sitemap:toolbar.html.twig', array('node' => $node, 'multi_language_enabled' => $this->routerHelper->multiLanguageIsEnabled(), 'multi_language_locales' => $this->routerHelper->getMultiLanguageLocales(), 'has_controller' => $this->routerHelper->hasController($node->getType()))); }
/** * Render node content template. * * @param NodeInterface $node * @param array $tabs * * @return string */ public function renderNodeContent(NodeInterface $node, array $tabs) { return $this->responseHelper->render('TadckaSitemapBundle:Sitemap:content.html.twig', array('node' => $node, 'tabs' => $tabs, 'has_controller' => $this->routerHelper->hasController($node->getType()), 'multi_language_enabled' => $this->routerHelper->multiLanguageIsEnabled(), 'multi_language_locales' => $this->routerHelper->getMultiLanguageLocales())); }
public function testHasController() { $this->assertFalse($this->routerHelper->hasController('fake')); $this->assertTrue($this->routerHelper->hasController('test')); }