From: Vincent Vanwaelscappel Date: Tue, 31 Dec 2019 12:19:11 +0000 (+0100) Subject: wip #3294 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=64b9c0128943c90ebe1b1ff35e37b5feeb12276e;p=cubist_cms-back.git wip #3294 @0.5 --- diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index ed6c642..447c06c 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -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; + } }