Adds a method for defining which settings and viewBag properties should be visible as native ones
This commit is contained in:
parent
b81efa9c46
commit
dbba9349ab
|
|
@ -56,10 +56,14 @@ class CmsCompoundObject extends CmsObject
|
|||
'fileName'
|
||||
];
|
||||
|
||||
protected $settingsVisible = [];
|
||||
|
||||
protected $settingsValidationRules = [];
|
||||
|
||||
protected $settingsValidationMessages = [];
|
||||
|
||||
protected $viewBagVisible = [];
|
||||
|
||||
protected $viewBagValidationRules = [];
|
||||
|
||||
protected $viewBagValidationMessages = [];
|
||||
|
|
@ -106,10 +110,22 @@ class CmsCompoundObject extends CmsObject
|
|||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if (is_array($this->settings) && array_key_exists($name, $this->settings)) {
|
||||
if (
|
||||
is_array($this->settings) &&
|
||||
array_key_exists($name, $this->settings) &&
|
||||
array_key_exists($name, array_flip($this->settingsVisible))
|
||||
) {
|
||||
return $this->settings[$name];
|
||||
}
|
||||
|
||||
if (
|
||||
is_array($this->viewBag) &&
|
||||
array_key_exists($name, $this->viewBag) &&
|
||||
array_key_exists($name, array_flip($this->viewBagVisible))
|
||||
) {
|
||||
return $this->viewBag[$name];
|
||||
}
|
||||
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +141,10 @@ class CmsCompoundObject extends CmsObject
|
|||
return true;
|
||||
}
|
||||
|
||||
if (isset($this->viewBag[$key]) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isset($this->settings[$key]);
|
||||
}
|
||||
|
||||
|
|
@ -452,9 +472,10 @@ class CmsCompoundObject extends CmsObject
|
|||
*/
|
||||
protected function initFromCache($cached)
|
||||
{
|
||||
$this->settings = $cached['settings'];
|
||||
$this->code = $cached['code'];
|
||||
$this->markup = $cached['markup'];
|
||||
$this->viewBag = array_get($cached, 'viewBag', []);
|
||||
$this->settings = array_get($cached, 'settings', []);
|
||||
$this->code = array_get($cached, 'code');
|
||||
$this->markup = array_get($cached, 'markup');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -463,6 +484,7 @@ class CmsCompoundObject extends CmsObject
|
|||
*/
|
||||
protected function initCacheItem(&$item)
|
||||
{
|
||||
$item['viewBag'] = $this->viewBag;
|
||||
$item['settings'] = $this->settings;
|
||||
$item['code'] = $this->code;
|
||||
$item['markup'] = $this->markup;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,13 @@ class Layout extends CmsCompoundObject
|
|||
{
|
||||
const FALLBACK_FILE_NAME = 'fallback';
|
||||
|
||||
/**
|
||||
* @var array These settings properties will be available as regular properties.
|
||||
*/
|
||||
protected $settingsVisible = [
|
||||
'description'
|
||||
];
|
||||
|
||||
protected function parseSettings()
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,19 @@ class Page extends CmsCompoundObject
|
|||
*/
|
||||
public $apiBag = [];
|
||||
|
||||
/**
|
||||
* @var array These settings properties will be available as regular properties.
|
||||
*/
|
||||
protected $settingsVisible = [
|
||||
'title',
|
||||
'url',
|
||||
'layout',
|
||||
'description',
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
'hidden'
|
||||
];
|
||||
|
||||
protected $settingsValidationRules = [
|
||||
'title' => 'required',
|
||||
'url' => ['required', 'regex:/^\/[a-z0-9\/\:_\-\*\[\]\+\?\|\.\^\$]*$/i']
|
||||
|
|
|
|||
|
|
@ -8,6 +8,13 @@
|
|||
*/
|
||||
class Partial extends CmsCompoundObject
|
||||
{
|
||||
/**
|
||||
* @var array These settings properties will be available as regular properties.
|
||||
*/
|
||||
protected $settingsVisible = [
|
||||
'description'
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns the directory name corresponding to the object type.
|
||||
* For pages the directory name is "pages", for layouts - "layouts", etc.
|
||||
|
|
|
|||
Loading…
Reference in New Issue