diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index 2aace50f9..e6a2f5a00 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -396,6 +396,15 @@ class Theme return $this->getConfigValue('form', false); } + /** + * Returns data specific to this theme + * @return Cms\Models\ThemeData + */ + public function getCustomData() + { + return ThemeData::forTheme($this); + } + /** * Ensures this theme is registered as a Halcyon them datasource. * @return void @@ -418,7 +427,7 @@ class Theme public function __get($name) { if ($this->hasCustomData()) { - $theme = ThemeData::forTheme($this); + $theme = $this->getCustomData(); return $theme->{$name}; } @@ -433,11 +442,10 @@ class Theme public function __isset($key) { if ($this->hasCustomData()) { - $theme = ThemeData::forTheme($this); - return isset($theme->{$key}); + $theme = $this->getCustomData(); + return $theme->offsetExists($key); } return false; } - } diff --git a/modules/cms/models/ThemeData.php b/modules/cms/models/ThemeData.php index 4e2e0ba0b..1b02a99e2 100644 --- a/modules/cms/models/ThemeData.php +++ b/modules/cms/models/ThemeData.php @@ -3,6 +3,7 @@ use Lang; use Model; use Cms\Classes\Theme as CmsTheme; +use System\Classes\CombineAssets; /** * Customization data used by a theme @@ -39,6 +40,11 @@ class ThemeData extends Model */ public $rules = []; + /** + * @var array Relations + */ + public $attachOne = []; + /** * @var ThemeData Cached array of objects */ @@ -56,6 +62,11 @@ class ThemeData extends Model $this->setRawAttributes(array_only($this->getAttributes(), $staticAttributes)); } + public function afterSave() + { + CombineAssets::resetCache(); + } + /** * Returns a cached version of this model, based on a Theme object. * @param $theme Cms\Classes\Theme @@ -78,9 +89,16 @@ class ThemeData extends Model * Repeater form fields store arrays and must be jsonable. */ foreach ($this->getFormFields() as $id => $field) { - if (isset($field['type']) && $field['type'] == 'repeater') { + if (!isset($field['type'])) { + continue; + } + + if ($field['type'] == 'repeater') { $this->jsonable[] = $id; } + elseif ($field['type'] == 'fileupload') { + $this->attachOne[$id] = 'System\Models\File'; + } } /* @@ -91,8 +109,9 @@ class ThemeData extends Model public function beforeValidate() { - if (!$this->exists) + if (!$this->exists) { $this->setDefaultValues(); + } } /** @@ -119,6 +138,7 @@ class ThemeData extends Model /** * Returns all fields defined for this model, based on form field definitions. + * @return array */ public function getFormFields() { @@ -129,4 +149,23 @@ class ThemeData extends Model $theme->getConfigValue('form.tabs.fields', []) + $theme->getConfigValue('form.secondaryTabs.fields', []); } + + /** + * Returns variables that should be passed to the asset combiner. + * @return array + */ + public function getAssetVariables() + { + $result = []; + + foreach ($this->getFormFields() as $attribute => $field) { + if (!$varName = array_get($field, 'assetVar')) { + continue; + } + + $result[$varName] = $this->{$attribute}; + } + + return $result; + } } diff --git a/modules/cms/reportwidgets/activetheme/partials/_widget.htm b/modules/cms/reportwidgets/activetheme/partials/_widget.htm index e3174541a..39c7503a8 100644 --- a/modules/cms/reportwidgets/activetheme/partials/_widget.htm +++ b/modules/cms/reportwidgets/activetheme/partials/_widget.htm @@ -24,6 +24,14 @@