/** * Create node translation route. * * @param NodeTranslationInterface $translation * * @return RouteInterface */ public function create(NodeTranslationInterface $translation) { $locale = $translation->getLang(); $node = $translation->getNode(); $route = $this->routeManager->create(); $route->setRoutePattern($this->routerHelper->getRoutePattern($translation->getTitle(), $node, $locale)); $this->routeGenerator->generateRoute($route, $node, $locale); $this->routeManager->add($route); return $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); } }
public function testNormalizeRoutePattern() { $this->assertEquals('', $this->routerHelper->normalizeRoutePattern('')); $this->assertEquals('/bump-bump', $this->routerHelper->normalizeRoutePattern('bump bump')); $this->assertEquals('/bump/bump', $this->routerHelper->normalizeRoutePattern('bump/bump/')); $this->assertEquals('/bump/bump', $this->routerHelper->normalizeRoutePattern(' /bump / bump')); $this->assertEquals('/bump/bump-test', $this->routerHelper->normalizeRoutePattern('/bump/bump test')); $this->assertEquals('/bump-test/bump', $this->routerHelper->normalizeRoutePattern('/bump test/bump')); }
/** * Get unique route pattern. * * @param RouteInterface $route * * @return string */ private function getUniqueRoutePattern(RouteInterface $route) { $key = 0; $originalRoutePattern = $this->routerHelper->normalizeRoutePattern($route->getRoutePattern()); $routePattern = $originalRoutePattern; while ($this->hasRoute($route->getName(), $routePattern)) { $key++; $routePattern = $originalRoutePattern . '-' . $key; } return $routePattern; }
/** * 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()))); }
/** * Checks if the passed node is valid. * * @param NodeTranslationInterface $nodeTranslation * @param Constraint|NodeRouteNotEmpty $constraint */ public function validate($nodeTranslation, Constraint $constraint) { if (false === $this->routeHelper->hasRoute($nodeTranslation->getLang(), $nodeTranslation->getNode())) { $this->context->addViolation($constraint->message, array('%locale%' => $nodeTranslation->getLang())); } }
/** * 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())); }