]> _ Git - cubist_cms-back.git/commitdiff
wip #3520 @6
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Mar 2020 11:12:17 +0000 (13:12 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Mar 2020 11:12:17 +0000 (13:12 +0200)
src/app/Magic/EntityData.php
src/app/Magic/Models/CMSPage.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index 517ab0ffe55df41d51f6b7f879cb3eeb54333c30..ded15fcc5335ad5fea233efd3af548304adca190 100644 (file)
@@ -101,6 +101,11 @@ class EntityData implements \ArrayAccess
      * @return mixed
      */
     public function get($offset, $default = null)
+    {
+        return $this->_get($offset, false, $default);
+    }
+
+    protected function _get($offset, $withTranslations = false, $default = null)
     {
         if (!is_array($offset)) {
             $offset = [$offset];
@@ -123,7 +128,9 @@ class EntityData implements \ArrayAccess
             // We have to check if the key exists because the actual value may be null.
             // Using isset() on the locale key would give a false negative if the value is null.
             if (is_array($res) && array_key_exists(App::getLocale(), $res)) {
-                $res = $res[App::getLocale()];
+                if (!$withTranslations) {
+                    $res = $res[App::getLocale()];
+                }
             }
 
             if (null === $res) {
@@ -135,6 +142,11 @@ class EntityData implements \ArrayAccess
         return $default;
     }
 
+    public function getWithTranslations($offset, $default = null)
+    {
+        return $this->_get($offset, true, $default);
+    }
+
     /**
      * @param mixed $offset
      * @param mixed $value
index 532e20963e317d5a380da890a62fb2af3e8553ea..0c824dffb1cb9f68fa83a41308d6377d67749f67 100644 (file)
@@ -22,11 +22,6 @@ class CMSPage extends CubistMagicNestedModel
     protected static $_table = 'cubist_cms_pages';
     protected $table = 'cubist_cms_pages';
 
-    /**
-     * @var TemplateAbstract
-     */
-    protected static $_tree = null;
-
     protected $_options = ['name' => 'page',
         'singular' => 'page',
         'plural' => 'pages'];
@@ -261,6 +256,6 @@ class CMSPage extends CubistMagicNestedModel
         if ($this instanceof CMSPage) {
             $this->useTemplate();
         }
-        parent::copyTranslations($from, $to, $overwrite); // TODO: Change the autogenerated stub
+        parent::copyTranslations($from, $to, $overwrite);
     }
 }
index 38e822e3109c85a56824e811974c9140bbab4b28..86f86d8d3aa83dd2daec20fabe68a9c703be0785 100644 (file)
@@ -535,31 +535,35 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     /**
      * @return EntityData
      */
-    public function getEntityData()
+    public function getEntityData($keepTranslations = false)
     {
-        $this->withFakes();
-
-        $res = new EntityData();
-        $res->setEntity($this);
-        foreach ($this->attributes as $key => $value) {
-            $res->set($key, Json::decodeRecursive($this->getAttributeValue($key), Json::TYPE_ARRAY));
-        }
-        return $res;
+        return $this->_fillData(new EntityData(), $keepTranslations);
     }
 
     /**
      * @return PageData
      */
-    public function getPageData()
+    public function getPageData($keepTranslations = false)
     {
-        $this->withFakes();
+        return $this->_fillData(new PageData(), $keepTranslations);
+    }
 
-        $res = new PageData();
-        $res->setEntity($this);
+    /**
+     * @param EntityData $d
+     * @param bool $keepTranslations
+     * @return EntityData|PageData
+     */
+    protected function _fillData(EntityData $d, $keepTranslations = false)
+    {
+        $this->withFakes();
+        $d->setEntity($this);
         foreach ($this->attributes as $key => $value) {
-            $res->set($key, Json::decodeRecursive($this->getAttributeValue($key), Json::TYPE_ARRAY));
+            if (!$keepTranslations) {
+                $value = $this->getAttributeValue($key);
+            }
+            $d->set($key, Json::decodeRecursive($value, Json::TYPE_ARRAY));
         }
-        return $res;
+        return $d;
     }
 
     public function getMediaInField($c)