From bbf025d02159b3fadfed0b634f29cf9f8fd2db4f Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 10 Jul 2019 20:21:43 +0200 Subject: [PATCH] #2878 --- src/app/Magic/Menu/Item.php | 45 ++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index 6ba8316..db2e6af 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -41,6 +41,12 @@ class Item */ protected $_classes = []; + + /** + * @var string + */ + protected $_type = ''; + /** * @param string $id */ @@ -81,6 +87,22 @@ class Item $this->addChild($child); } + /** + * @return string + */ + public function getType(): string + { + return $this->_type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->_type = $type; + } + /** * @return mixed */ @@ -132,7 +154,7 @@ class Item /** * @return string */ - public function getTitle(): string + public function getTitle() { return $this->_title; } @@ -140,7 +162,7 @@ class Item /** * @param string $title */ - public function setTitle(string $title): void + public function setTitle($title) { $this->_title = $title; } @@ -209,15 +231,26 @@ class Item // Handle items with submenus if ($child->hasChildren()) { // Create an empty sub-element that will serve as a wrapper for the submenu(s) - $wrapper = $parent->raw('')->attr(['class' => 'nav-submenu-wrapper']); + + + 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 { // // Some submenus have a title element // if (isset($submenu_data['title'])) { // $wrapper->raw($submenu_data['title'])->attr(['class' => 'nav-submenu-title']); // } - - foreach ($child->getChildren() as $subitem) { - $wrapper->add($subitem->getTitle(), $subitem->getHref()); + $wrapper = $parent->raw('')->attr(['class' => 'nav-submenu-wrapper']); + foreach ($child->getChildren() as $subitem) { + $wrapper->add($subitem->getTitle(), $subitem->getHref()); + } } } } -- 2.39.5