]> _ Git - cubist_cms-back.git/commitdiff
wip #3294 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Dec 2019 16:45:15 +0000 (17:45 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Dec 2019 16:45:15 +0000 (17:45 +0100)
src/app/Magic/Menu/Item.php
src/app/Magic/Menu/PageItem.php

index 447c06c1580f78f61169a2690c65614b3b42a169..a52978e410939cc7c5e6183f9742ad892c921208 100644 (file)
@@ -4,13 +4,20 @@
 namespace Cubist\Backpack\app\Magic\Menu;
 
 use Cubist\Backpack\app\Magic\Models\CMSPage;
+use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel;
 use Cubist\Backpack\app\Magic\Models\Locale;
+use Cubist\Backpack\app\Magic\PageData;
 use Cubist\Backpack\app\Template\Navigation;
+use Illuminate\Database\Eloquent\Model;
 use Illuminate\Support\Facades\App;
 use Illuminate\Support\Str;
+use stdClass;
 
 class Item
 {
+    /** @var Item */
+    protected $_root;
+
     /** @var Item */
     protected $_parent;
 
@@ -99,6 +106,11 @@ class Item
      */
     protected $_locale = '';
 
+    /**
+     * @var CubistMagicPageModel
+     */
+    protected $_entity;
+
 
     /**
      * @param string $id
@@ -111,6 +123,7 @@ class Item
         $all = $class::orderBy('lft')->get();
 
         $this->setId('#root');
+        $this->setRoot($this);
         $this->setBreadcrumbs(false);
         $this->setName($id);
         $this->setChildrenFromData($all, null);
@@ -140,6 +153,7 @@ class Item
     public function addChildFromData($data, $all)
     {
         $child = new PageItem();
+        $child->setEntity($data);
         $child->setLocale($this->getLocale());
         if ($data->getUsedTemplate() instanceof Navigation) {
             $child->setBreadcrumbs(false);
@@ -435,7 +449,8 @@ class Item
      */
     public function addChild($item)
     {
-        if ($item->getRawLocale() === '') {
+        $locale = $item->getRawLocale();
+        if (!$locale) {
             $item->setLocale($this->getLocale());
         }
         $item->setParent($this);
@@ -595,7 +610,11 @@ class Item
             return $this;
         }
         $res = Menu::getNavigation($locale)->findOneById($this->getId());
-        if (!$strict && null === $res && null !== $this->getParent()) {
+        if (!$strict && null === $res) {
+            if (null === $this->getParent()) {
+                return $this->getRoot()->findOneById('home')->getTranslatedPage($locale, $strict);
+
+            }
             return $this->getParent()->getTranslatedPage($locale, $strict);
         }
         return $res;
@@ -665,5 +684,48 @@ class Item
     public function setParent(Item $parent): void
     {
         $this->_parent = $parent;
+        $root = $parent->getRoot();
+        if ($root !== null) {
+            $this->setRoot($root);
+        }
+    }
+
+    /**
+     * @return Item
+     */
+    public function getRoot()
+    {
+        return $this->_root;
+    }
+
+    /**
+     * @param Item $root
+     */
+    public function setRoot(Item $root): void
+    {
+        $this->_root = $root;
+    }
+
+    /**
+     * @param CubistMagicPageModel $entity
+     */
+    public function setEntity(CubistMagicPageModel $entity): void
+    {
+        $this->_entity = $entity;
+    }
+
+    /**
+     * @return CubistMagicPageModel
+     */
+    public function getEntity(): CubistMagicPageModel
+    {
+        return $this->_entity;
+    }
+
+    /**
+     * @return PageData
+     */
+    public function getPageData(){
+        return $this->getEntity()->getPageData();
     }
 }
index 49a04483379aeb4bc9bfc5bb58d159b6f9ae0e09..91d087636ab35abca1e315234aee30e70c1e6451 100644 (file)
@@ -45,6 +45,8 @@ class PageItem extends Item
         }
         $data = $entity->getPageData();
 
+        $this->setEntity($entity);
+
         $this->setId($data->get('id'));
         $this->setName($data->get('name', get_class($entity) . '_' . $data->get('id')));
         $this->setSlug($data->get('slug'));