From: Vincent Vanwaelscappel Date: Mon, 30 Mar 2020 11:12:17 +0000 (+0200) Subject: wip #3520 @6 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c2ee466553e8664ea2e859458243873ef58c49ce;p=cubist_cms-back.git wip #3520 @6 --- diff --git a/src/app/Magic/EntityData.php b/src/app/Magic/EntityData.php index 517ab0f..ded15fc 100644 --- a/src/app/Magic/EntityData.php +++ b/src/app/Magic/EntityData.php @@ -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 diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 532e209..0c824df 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -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); } } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 38e822e..86f86d8 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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)