Example #1
0
 /**
  * Creates a menu item link element
  *
  * @param Menu $menu
  *
  * @return string
  */
 public function createLink(Menu $menu)
 {
     if ($menu->getIcon() && strpos($menu->getIcon(), '.') === false) {
         return sprintf('<a href="%s"%s><i aria-hidden="true" class="icon-%s"></i>%s</a>', $menu->getUrl() ?: '#', $this->getAttributes(), $menu->getIcon(), $this->getView()->escape($menu->getTitle()));
     }
     return sprintf('<a href="%s"%s>%s%s<span></span></a>', $menu->getUrl() ?: '#', $this->getAttributes(), $menu->getIcon() ? '<img aria-hidden="true" src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '', $this->getView()->escape($menu->getTitle()));
 }
 /**
  * Renders the html content of a single menu item and summarized sub-menus
  *
  * @param Menu $menu
  *
  * @return string
  */
 public function render(Menu $menu)
 {
     /** @var $submenu Menu */
     foreach ($menu->getSubMenus() as $submenu) {
         $renderer = $submenu->getRenderer();
         if ($renderer instanceof BadgeMenuItemRenderer) {
             if ($renderer->getState() === $this->state) {
                 $this->titles[] = $renderer->getTitle();
                 $this->count += $renderer->getCount();
             }
         }
     }
     return $this->renderBadge() . $this->createLink($menu);
 }
 /**
  * Renders the html content of a single menu item and summarizes submenu problems
  *
  * @param Menu $menu
  *
  * @return string
  */
 public function render(Menu $menu)
 {
     if ($menu->getParent() !== null && $menu->hasSubMenus()) {
         /** @var $submenu Menu */
         foreach ($menu->getSubMenus() as $submenu) {
             $renderer = $submenu->getRenderer();
             if (method_exists($renderer, 'getSummary')) {
                 if ($renderer->getSummary() !== null) {
                     $this->summary[] = $renderer->getSummary();
                 }
             }
         }
     }
     return $this->getBadge() . $this->createLink($menu);
 }
Example #4
0
 /**
  * Render the menu
  */
 public function menuAction()
 {
     $this->setAutorefreshInterval(15);
     $this->_helper->layout()->disableLayout();
     $url = Url::fromRequest();
     $menu = new MenuRenderer(Menu::load(), $url->getRelativeUrl());
     $this->view->menuRenderer = $menu->useCustomRenderer();
 }
Example #5
0
 public function testWhetherMenusAreNaturallySorted()
 {
     $menu = new Menu('test');
     $menu->addSubMenu(5, new ConfigObject(array('title' => 'ccc5')));
     $menu->addSubMenu(0, new ConfigObject(array('title' => 'aaa')));
     $menu->addSubMenu(3, new ConfigObject(array('title' => 'ccc')));
     $menu->addSubMenu(2, new ConfigObject(array('title' => 'bbb')));
     $menu->addSubMenu(4, new ConfigObject(array('title' => 'ccc2')));
     $menu->addSubMenu(1, new ConfigObject(array('title' => 'bb')));
     $this->assertEquals(array('aaa', 'bb', 'bbb', 'ccc', 'ccc2', 'ccc5'), array_map(function ($m) {
         return $m->getTitle();
     }, iterator_to_array($menu->order())), 'Menu::order() does not return its elements in natural order');
 }
Example #6
0
 /**
  * Compare sub menus based on priority and title
  *
  * @param   Menu    $a
  * @param   Menu    $b
  *
  * @return  int
  */
 protected function cmpSubMenus($a, $b)
 {
     if ($a->priority == $b->priority) {
         return $a->getTitle() > $b->getTitle() ? 1 : ($a->getTitle() < $b->getTitle() ? -1 : 0);
     }
     return $a->priority > $b->priority ? 1 : -1;
 }
Example #7
0
 /**
  * Return whether the current request url references the child's url
  *
  * @param   Menu    $child      The menu's child to check
  *
  * @return  bool
  */
 protected function isActive(Menu $child)
 {
     if (!$this->url) {
         return false;
     }
     if (!($childUrl = $child->getUrl())) {
         return false;
     }
     return $this->url && $this->url->matches($childUrl);
 }