Exemplo n.º 1
0
 /**
  * Validate by parent.
  *
  * @param string $nodeType
  * @param NodeInterface $parent
  *
  * @return bool
  */
 public function validateByParent($nodeType, NodeInterface $parent = null)
 {
     if (!$nodeType) {
         return true;
     }
     $config = $this->getNodeTypeConfig($nodeType);
     if (null === $config) {
         return false;
     }
     if (null !== $parent && $parent->getType()) {
         return in_array($parent->getType(), $config->getParentTypes());
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Checks if the passed node type is valid.
  *
  * @param NodeInterface $node
  * @param Constraint $constraint
  */
 public function validate($node, Constraint $constraint)
 {
     if (!in_array($node->getType(), $this->nodeProvider->getActiveNodeTypes($node))) {
         $nodeTypeName = $node->getType();
         if (null !== ($config = $this->nodeProvider->getNodeTypeConfig($node->getType()))) {
             $nodeTypeName = $config->getName();
         }
         $this->context->addViolation($constraint->message, array('%node_type%' => $nodeTypeName));
     }
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getActiveNodeTypes(NodeInterface $node)
 {
     $nodeTypes = array();
     foreach ($this->nodeTypeRegistry->getConfigs() as $config) {
         if ($node->getType() === $config->getType() || $this->nodeValidator->validateByOnlyOne($config->getType(), $node->getTree()) && (!$config->getParentTypes() || $this->nodeValidator->validateByParent($config->getType(), $node->getParent()))) {
             $nodeTypes[$config->getType()] = $config->getType();
         }
     }
     return array_values($nodeTypes);
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
 /**
  * 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())));
 }
Exemplo n.º 6
0
 /**
  * Get route full path.
  *
  * @param NodeInterface $node
  * @param string $locale
  *
  * @return string
  */
 private function getRouteFullPath(NodeInterface $node, $locale)
 {
     $path = '';
     if ($this->hasController($node->getType())) {
         $parent = $node->getParent();
         if (null !== $parent && $this->hasController($parent->getType())) {
             $path = $this->getRouteFullPath($parent, $locale);
         }
         if (null !== ($translation = $node->getTranslation($locale))) {
             $path .= $this->normalizeRoutePattern($translation->getTitle());
         }
     }
     return $path;
 }
Exemplo n.º 7
0
 /**
  * Get node icon.
  *
  * @param NodeInterface $node
  *
  * @return null|string
  */
 private function getIcon(NodeInterface $node)
 {
     if (null === $node->getParent()) {
         return $this->getRootNodeIcon();
     }
     if ($node->getType() && null !== ($config = $this->nodeProvider->getNodeTypeConfig($node->getType()))) {
         return $config->getIconPath();
     }
     return null;
 }
 /**
  * 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()));
 }
Exemplo n.º 9
0
 /**
  * Delete node route.
  *
  * @param NodeInterface $node
  * @param RouteInterface $route
  */
 private function deleteNodeRoute(NodeInterface $node, RouteInterface $route)
 {
     $this->routeManager->remove($route);
     $redirectRouteName = $route->getDefault('redirectRouteName');
     if (RedirectRoute::NODE_TYPE === $node->getType() && null !== $redirectRouteName) {
         $redirectRoute = $this->redirectRouteManager->findByName($redirectRouteName);
         if (null !== $redirectRoute) {
             $this->redirectRouteManager->remove($redirectRoute);
         }
     }
 }