]> _ Git - cubist_cms-back.git/commitdiff
wip #3294 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Dec 2019 12:19:11 +0000 (13:19 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Dec 2019 12:19:11 +0000 (13:19 +0100)
src/app/Magic/Menu/Item.php

index ed6c642afa8710e11e9f83c718b07b12a348554b..447c06c1580f78f61169a2690c65614b3b42a169 100644 (file)
@@ -11,6 +11,9 @@ use Illuminate\Support\Str;
 
 class Item
 {
+    /** @var Item */
+    protected $_parent;
+
     /** @var Item[] */
     protected $_children = [];
 
@@ -435,6 +438,7 @@ class Item
         if ($item->getRawLocale() === '') {
             $item->setLocale($this->getLocale());
         }
+        $item->setParent($this);
         $this->_children[] = $item;
     }
 
@@ -580,12 +584,20 @@ class Item
         return $this->_robots;
     }
 
-    public function getTranslatedPage($locale)
+    /**
+     * @param $locale
+     * @param bool $strict
+     * @return $this|Item|null
+     */
+    public function getTranslatedPage($locale, $strict = true)
     {
         if ($this->getLocale() === $locale) {
             return $this;
         }
         $res = Menu::getNavigation($locale)->findOneById($this->getId());
+        if (!$strict && null === $res && null !== $this->getParent()) {
+            return $this->getParent()->getTranslatedPage($locale, $strict);
+        }
         return $res;
     }
 
@@ -638,4 +650,20 @@ class Item
         $this->setMenuDesktopChildren($val);
         $this->setMenuMobileChildren($val);
     }
+
+    /**
+     * @return Item
+     */
+    public function getParent()
+    {
+        return $this->_parent;
+    }
+
+    /**
+     * @param Item $parent
+     */
+    public function setParent(Item $parent): void
+    {
+        $this->_parent = $parent;
+    }
 }