{
$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());
- }
- }
- }
- }
- }
}
*/
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();
}
*/
public static function getAllNavigablePages()
{
- $pages = Menu::getNavigation()->findAll();
+ $pages = self::getNavigation()->findAll();
$res = [];
{
$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
}
}
+ 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 = '<div class="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList">';