From 12ef50abd9da012ebe1023a5814302f4798ced84 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 31 Dec 2019 17:45:15 +0100 Subject: [PATCH] wip #3294 @1 --- src/app/Magic/Menu/Item.php | 66 ++++++++++++++++++++++++++++++++- src/app/Magic/Menu/PageItem.php | 2 + 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index 447c06c..a52978e 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -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(); } } diff --git a/src/app/Magic/Menu/PageItem.php b/src/app/Magic/Menu/PageItem.php index 49a0448..91d0876 100644 --- a/src/app/Magic/Menu/PageItem.php +++ b/src/app/Magic/Menu/PageItem.php @@ -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')); -- 2.39.5