From: Vincent Vanwaelscappel Date: Fri, 30 Aug 2019 17:08:22 +0000 (+0200) Subject: wip #2974 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=fc4271893211b87d175d189ac72cccca10643772;p=cubist_cms-back.git wip #2974 @0.5 --- diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index 1f845d2..a9e090c 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -455,34 +455,4 @@ class Item { $this->_urlAliases = $urlAliases; } - - /** - * @param $menu Menu - */ - public function makeMenu($menu) - { - foreach ($this->getChildren() as $child) { - $parent = $menu->add($child->getTitle(), $child->getHref()); - // Handle items with submenus - if ($child->hasChildren()) { - // Create an empty sub-element that will serve as a wrapper for the submenu(s) - - - if ($child->getType() == 'mega') { - foreach ($child->getChildren() as $submenu) { - $wrapper = $parent->raw('')->attr(['class' => 'nav-submenu-wrapper']); - $wrapper->raw($submenu->getTitle())->attr(['class' => 'nav-submenu-title']); - foreach ($submenu->getChildren() as $subitem) { - $wrapper->add($subitem->getTitle(), $subitem->getHref()); - } - } - } else { - $wrapper = $parent->raw('')->attr(['class' => 'nav-submenu-wrapper']); - foreach ($child->getChildren() as $subitem) { - $wrapper->add($subitem->getTitle(), $subitem->getHref()); - } - } - } - } - } } diff --git a/src/app/Magic/Menu/Menu.php b/src/app/Magic/Menu/Menu.php index 19e4872..eb0b0fa 100644 --- a/src/app/Magic/Menu/Menu.php +++ b/src/app/Magic/Menu/Menu.php @@ -14,8 +14,21 @@ class Menu extends BaseMenu */ protected static $_nav = null; - public function get($key) + protected const _STANDARD_PREFIX = 'cubist'; + + protected $_registeredMenuMakers = []; + + + public function registerMenuMaker($name, $callback) { + $this->_registeredMenuMakers[$name] = $callback; + } + + public function get($key, $name = self::_STANDARD_PREFIX) + { + if ($name) { + $key = $name . '_' . $key; + } if (!$this->exists($key)) { $this->makeAllMenus(); } @@ -45,7 +58,7 @@ class Menu extends BaseMenu */ public static function getAllNavigablePages() { - $pages = Menu::getNavigation()->findAll(); + $pages = self::getNavigation()->findAll(); $res = []; @@ -101,19 +114,42 @@ class Menu extends BaseMenu { $nav = self::getNavigation(); foreach ($nav->getChildren() as $main) { - $this->make($main->getName(), function ($menu) use ($main) { - $main->makeMenu($menu); - }); + $this->makeStandardMenus($main); } // Also make a menu for the breadcrumbs - this one is simpler and doesn't have the submenu headings - $this->make('breadcrumbs', function ($menu) use ($nav) { + $this->make(self::_STANDARD_PREFIX . '_breadcrumbs', function ($menu) use ($nav) { // Start with home link $menu = $menu->add(__('Accueil'), ''); $this->_addToBreadcrumbs($nav, $menu); }); } + public function makeStandardMenus($item) + { + $this->make(self::_STANDARD_PREFIX . '_' . $item->getName(), function ($menu) use ($item) { + $this->makeStandardMenu($menu, $item); + }); + foreach ($this->_registeredMenuMakers as $name => $registeredMenuMaker) { + $this->make($name . '_' . $item->getName(), function ($menu) use ($item, $registeredMenuMaker) { + call_user_func($registeredMenuMaker, $menu, $item); + }); + } + } + + public function makeStandardMenu($menu, $item) + { + foreach ($item->getChildren() as $child) { + $parent = $menu->add($child->getTitle(), $child->getHref()); + // Handle items with submenus + if ($child->hasChildren()) { + foreach ($child->getChildren() as $subitem) { + $parent->add($subitem->getTitle(), $subitem->getHref()); + } + } + } + } + /** * @param $nav Item * @param $menu \Lavary\Menu\Item @@ -136,6 +172,14 @@ class Menu extends BaseMenu } } + public function getSearchBreadcrumbs() + { + foreach ($this->get('breadcrumbs')->crumbMenu()->all() as $item) { + $search_breadcrumbs[] = ['title' => $item->title, 'url' => $item->url()]; + } + return $search_breadcrumbs; + } + public function breadcrumbs() { $res = '