From: Vincent Vanwaelscappel Date: Fri, 3 Jan 2020 17:25:35 +0000 (+0100) Subject: fix #3304 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=5407f2affe02b0f05ead9a229322aac3cb632317;p=cubist_cms-back.git fix #3304 @2 --- diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index a52978e..0b0f502 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -8,10 +8,8 @@ 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 { @@ -111,6 +109,9 @@ class Item */ protected $_entity; + protected $_entityClass; + protected $_entityId; + /** * @param string $id @@ -711,6 +712,8 @@ class Item */ public function setEntity(CubistMagicPageModel $entity): void { + $this->_entityClass = get_class($entity); + $this->_entityId = $entity->getIdValue(); $this->_entity = $entity; } @@ -719,13 +722,23 @@ class Item */ public function getEntity(): CubistMagicPageModel { + if (!isset($this->_entity)) { + $class = $this->_entityClass; + $this->_entity = $class::find($this->_entityId); + } return $this->_entity; } /** * @return PageData */ - public function getPageData(){ + public function getPageData() + { return $this->getEntity()->getPageData(); } + + public function __sleep() + { + return array_diff(array_keys(get_object_vars($this)), ['_entity']); + } }