]> _ Git - cubist_cms-back.git/commitdiff
wip #3593 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Apr 2020 13:39:12 +0000 (15:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Apr 2020 13:39:12 +0000 (15:39 +0200)
src/app/Magic/Menu/Item.php

index a70e56652c67e4766e060f6aac768f777296955f..443831c478a848aa269f1ba3370943d95627726b 100644 (file)
@@ -13,9 +13,6 @@ use Illuminate\Support\Str;
 
 class Item
 {
-    /** @var Item */
-    protected $_root;
-
     /** @var Item */
     protected $_parent;
 
@@ -135,7 +132,6 @@ class Item
         $all = $class::whereVariant($this->getVariant())->orderBy('lft')->get();
 
         $this->setId('#root');
-        $this->setRoot($this);
         $this->setBreadcrumbs(false);
         $this->setName($id);
         $this->setChildrenFromData($all, null);
@@ -170,8 +166,8 @@ class Item
         if ($data->getUsedTemplate() instanceof Navigation) {
             $child->setBreadcrumbs(false);
         }
-        $child->initFromPage($data, $all);
         $this->addChild($child);
+        $child->initFromPage($data, $all);
     }
 
     /**
@@ -443,7 +439,7 @@ class Item
 
     public function getCanonicalURL(): string
     {
-        $canonical = $this->getCanonical() || $this->getHref();
+        $canonical = $this->getCanonical() === '' ? $this->getHref() : $this->getCanonical();
         return $this->_getURL($canonical);
     }
 
@@ -742,10 +738,6 @@ class Item
     public function setParent(Item $parent): void
     {
         $this->_parent = $parent;
-        $root = $parent->getRoot();
-        if ($root !== null) {
-            $this->setRoot($root);
-        }
     }
 
     /**
@@ -753,15 +745,10 @@ class Item
      */
     public function getRoot()
     {
-        return $this->_root;
-    }
-
-    /**
-     * @param Item $root
-     */
-    public function setRoot(Item $root): void
-    {
-        $this->_root = $root;
+        if ($this->getParent() === null) {
+            return $this;
+        }
+        return $this->getParent()->getRoot();
     }
 
     /**