]> _ Git - cubist_cms-back.git/commitdiff
done #2902 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Jul 2019 11:38:12 +0000 (13:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Jul 2019 11:38:12 +0000 (13:38 +0200)
src/app/Magic/Menu/Item.php
src/app/Magic/Menu/Menu.php
src/app/Magic/Menu/PageItem.php

index 1b72f05b1b3b915f368b20d28d226ff9630798fd..7db0ade8751633d7418e1876912aeaa10ce7eb05 100644 (file)
@@ -4,6 +4,7 @@
 namespace Cubist\Backpack\app\Magic\Menu;
 
 use Cubist\Backpack\app\Magic\Models\CMSPage;
+use Cubist\Backpack\app\Template\Navigation;
 use Illuminate\Support\Str;
 
 class Item
@@ -54,6 +55,11 @@ class Item
      */
     protected $_controller = [];
 
+    /**
+     * @var bool
+     */
+    protected $_breadcrumbs = true;
+
 
     /**
      * @param string $id
@@ -66,6 +72,7 @@ class Item
         $all = $class::orderBy('lft')->get();
 
         $this->setId('#root');
+        $this->setBreadcrumbs(false);
         $this->setName($id);
         $this->setChildrenFromData($all, null);
     }
@@ -84,6 +91,7 @@ class Item
             if (!$item->status) {
                 continue;
             }
+
             $this->addChildFromData($item, $data);
         }
     }
@@ -94,6 +102,9 @@ class Item
     public function addChildFromData($data, $all)
     {
         $child = new PageItem();
+        if ($data->getUsedTemplate() instanceof Navigation) {
+            $child->setBreadcrumbs(false);
+        }
         $child->initFromPage($data, $all);
         $this->addChild($child);
     }
@@ -346,6 +357,27 @@ class Item
         $this->_controller = $controller;
     }
 
+    /**
+     * @param bool $breadcrumbs
+     */
+    public function setBreadcrumbs(bool $breadcrumbs): void
+    {
+        $this->_breadcrumbs = $breadcrumbs;
+    }
+
+    public function getBreadcrumbHref()
+    {
+        return $this->getHref();
+    }
+
+    /**
+     * @return bool
+     */
+    public function isBreadcrumbs(): bool
+    {
+        return $this->_breadcrumbs;
+    }
+
     /**
      * @param $menu Menu
      */
index 8fca83376696b4f67439b67a2baae38d53fb239c..6d7f68ae579482db8dac0de068e3defe419c381e 100644 (file)
@@ -50,20 +50,30 @@ class Menu extends BaseMenu
         // 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) {
             // Start with home link
-            $menu = $menu->add('Home', '');
-
-            foreach ($nav->getChildren() as $main) {
-                foreach ($main->getChildren() as $child) {
-                    $parent = $menu->add($child->getTitle(), $child->getHref());
+            $menu = $menu->add(__('Accueil'), '');
+            $this->_addToBreadcrumbs($nav, $menu);
+        });
+    }
 
-                    // 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
+     */
+    protected function _addToBreadcrumbs($nav, $menu)
+    {
+        if ($nav->getTitle() && $nav->isBreadcrumbs()) {
+            if (substr($nav->getBreadcrumbHref(), 0, 1) == '#') {
+                $parent = $menu->raw($nav->getTitle());
+            } else {
+                $parent = $menu->add($nav->getTitle(), $nav->getBreadcrumbHref());
             }
-        });
+        } else {
+            $parent = $menu;
+        }
+        if ($nav->hasChildren()) {
+            foreach ($nav->getChildren() as $child) {
+                $this->_addToBreadcrumbs($child, $parent);
+            }
+        }
     }
 }
index b6afc7da4fb799feefed21d46e73343fbad9aa5f..b866cedab5ba8c1c115ae733b81dc72f7c135ed1 100644 (file)
@@ -30,7 +30,7 @@ class PageItem extends Item
 
     public function setChildrenFromTemplate()
     {
-        $template=$this->getPage()->getUsedTemplate();
+        $template = $this->getPage()->getUsedTemplate();
         $template->setMenuChildren($this);
     }
 
@@ -52,6 +52,21 @@ class PageItem extends Item
         return $this->getSlug();
     }
 
+    public function getBreadcrumbHref()
+    {
+        if ($this->getPage()->template == 'first_redirection' && $this->hasChildren()) {
+            return '#';
+        } else if ($this->getPage()->template == 'internal_redirection') {
+            return '#';
+        } else if ($this->getPage()->template == 'redirection') {
+            return '#';
+        } else if ($this->getPage()->getUsedTemplate()->isVirtual()) {
+            return '#';
+        }
+
+        return $this->getHref();
+    }
+
     public function getClasses()
     {
         $classes = parent::getClasses();