* @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];
// 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) {
return $default;
}
+ public function getWithTranslations($offset, $default = null)
+ {
+ return $this->_get($offset, true, $default);
+ }
+
/**
* @param mixed $offset
* @param mixed $value
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'];
if ($this instanceof CMSPage) {
$this->useTemplate();
}
- parent::copyTranslations($from, $to, $overwrite); // TODO: Change the autogenerated stub
+ parent::copyTranslations($from, $to, $overwrite);
}
}
/**
* @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)