]> _ Git - cubist_cms-back.git/commitdiff
wip #3520 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Mar 2020 13:05:49 +0000 (15:05 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Mar 2020 13:05:49 +0000 (15:05 +0200)
src/app/Magic/Menu/Menu.php

index 75325e353c3b7025e0d046b6567d9f8890ab98e6..903e39760553299fc529a65f104b010e89680a71 100644 (file)
@@ -170,16 +170,22 @@ class Menu extends BaseMenu
     public function makeStandardMenu($menu, $item)
     {
         foreach ($item->getChildren() as $child) {
-            if (!$child->isMenuDesktop()) {
-                continue;
-            }
-            $parent = $menu->add($child->getTitle(), $child->getHref())->attr('data-name', $child->getName());
-            // Handle items with submenus
-            if ($child->isMenuDesktopChildren()) {
-                foreach ($child->getChildren() as $subitem) {
-                    $parent->add($subitem->getTitle(), $subitem->getHref())->attr('data-name', $subitem->getName());
-                }
-            }
+            $this->_addItem($menu, $child, 'isMenuDesktop');
+        }
+    }
+
+    protected function _addItem($menu, $item, $checkFunction)
+    {
+        $checkFunctionChildren = $checkFunction . 'Children';
+        if (!$item->$checkFunction()) {
+            return;
+        }
+        $parent = $menu->add($item->getTitle(), $item->getHref())->attr('data-name', $item->getName());
+        if (!$item->$checkFunctionChildren() || !$item->hasChildren()) {
+            return;
+        }
+        foreach ($item->getChildren() as $child) {
+            $this->_addItem($parent, $child, $checkFunction);
         }
     }