]> _ Git - cubist_cms-back.git/commitdiff
fix #3304 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 3 Jan 2020 17:25:35 +0000 (18:25 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 3 Jan 2020 17:25:35 +0000 (18:25 +0100)
src/app/Magic/Menu/Item.php

index a52978e410939cc7c5e6183f9742ad892c921208..0b0f502297b7e35d3b4c8442f751ce260fca9193 100644 (file)
@@ -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']);
+    }
 }