Exemplo n.º 1
0
 /**
  * Used by breadcrumbs to determine active link
  *
  * @param \Knp\Menu\ItemInterface $menu
  * @param string                  $forRouteUri
  * @param string                  $forRouteName
  *
  * @return \Knp\Menu\ItemInterface|null
  */
 public function getCurrentMenuItem($menu, $forRouteUri, $forRouteName)
 {
     try {
         /** @var \Knp\Menu\ItemInterface $item */
         foreach ($menu as $item) {
             if ($forRouteUri == "current" && $this->matcher->isCurrent($item)) {
                 //current match
                 return $item;
             } else {
                 if ($forRouteUri != "current" && $item->getUri() == $forRouteUri) {
                     //route uri match
                     return $item;
                 } else {
                     if (!empty($forRouteName) && $forRouteName == $item->getExtra("routeName")) {
                         //route name match
                         return $item;
                     }
                 }
             }
             if ($item->getChildren() && ($current_child = $this->getCurrentMenuItem($item, $forRouteUri, $forRouteName))) {
                 return $current_child;
             }
         }
     } catch (\Exception $e) {
         //do nothing
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * @param ItemInterface $rootItem
  *
  * @return ItemInterface|null
  */
 private function findFirstLevelActive(ItemInterface $rootItem)
 {
     foreach ($rootItem as $firstLevelItem) {
         if ($this->matcher->isCurrent($firstLevelItem) || $this->matcher->isAncestor($firstLevelItem)) {
             return $firstLevelItem;
         }
     }
     return;
 }
Exemplo n.º 3
0
 /**
  * Renders menu
  *
  * @param ItemInterface $item
  * @param array         $options
  *
  * @return string
  */
 public function render(ItemInterface $item, array $options = array())
 {
     $options = array_merge($this->defaultOptions, $options);
     if ($options['clear_matcher']) {
         $this->matcher->clear();
     }
     //render html
     $html = $this->engine->render($options['template'], array('item' => $item, 'options' => $options, 'matcher' => $this->matcher));
     return $html;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function matchItem(ItemInterface $item)
 {
     $children = $item->getChildren();
     $match = null;
     foreach ($children as $child) {
         if ($this->matcher->isCurrent($child)) {
             $match = true;
             break;
         }
     }
     return $match;
 }
 /**
  * @param ItemInterface|string $menu
  * @param array                $path
  * @param array                $options
  *
  * @return ItemInterface[]
  *
  * @throws \BadMethodCallException   when there is no menu provider and the menu is given by name
  * @throws \LogicException
  * @throws \InvalidArgumentException when the path is invalid
  */
 public function getCurrents($menu, array $path = array(), array $options = array())
 {
     $menu = $this->menuHelper->get($menu, $path, $options);
     $menuIterator = new \RecursiveIteratorIterator(new RecursiveItemIterator(new \ArrayIterator([$menu])), \RecursiveIteratorIterator::SELF_FIRST);
     $currents = [];
     foreach ($menuIterator as $item) {
         /** @var $item ItemInterface */
         if ($this->matcher->isCurrent($item)) {
             $currents[] = $item->getName();
         }
     }
     return $currents;
 }
Exemplo n.º 6
0
 /**
  * @param ItemInterface $item
  *
  * @return ItemInterface|null
  */
 private function retrieveCurrentItem(ItemInterface $item)
 {
     $currentItem = null;
     if ($this->matcher->isCurrent($item)) {
         return $item;
     }
     if ($this->matcher->isAncestor($item)) {
         foreach ($item->getChildren() as $child) {
             $currentItem = $this->retrieveCurrentItem($child);
             if (null !== $currentItem) {
                 break;
             }
         }
     }
     return $currentItem;
 }
Exemplo n.º 7
0
 /**
  * Renders menu
  *
  * @param ItemInterface $item
  * @param array         $options
  *
  * @return string
  */
 public function render(ItemInterface $item, array $options = array())
 {
     $options = array_merge($this->defaultOptions, $options);
     if ($options['clear_matcher']) {
         $this->matcher->clear();
     }
     $manipulator = new MenuManipulator();
     if ($options["menu"] == "admin") {
         //render html
         $html = $this->engine->render("MauticCoreBundle:Menu:admin.html.php", array("item" => $item, "options" => $options, "matcher" => $this->matcher));
     } else {
         //render html
         $html = $this->engine->render("MauticCoreBundle:Menu:main.html.php", array("item" => $item, "options" => $options, "matcher" => $this->matcher));
     }
     return $html;
 }
Exemplo n.º 8
0
 /**
  * @param ItemInterface    $menu
  * @param MatcherInterface $matcher
  *
  * @return bool
  */
 public function invisibleChildSelected($menu, MatcherInterface $matcher)
 {
     /** @var ItemInterface $item */
     foreach ($menu as $item) {
         if ($matcher->isCurrent($item)) {
             return $item->isDisplayed() ? false : true;
         }
     }
     return false;
 }