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 @@
  • + hasCustomData()): ?> +
  • + + Customize theme + +
  • +
    diff --git a/modules/system/classes/CombineAssets.php b/modules/system/classes/CombineAssets.php index a748e653f..217a51267 100644 --- a/modules/system/classes/CombineAssets.php +++ b/modules/system/classes/CombineAssets.php @@ -1,7 +1,7 @@ getFilters(File::extension($asset)) ?: []; + $filters = $this->processFilters($filters); $path = File::symbolizePath($asset, null) ?: $this->localPath . $asset; $files[] = new FileAsset($path, $filters, public_path()); $filesSalt .= $this->localPath . $asset; @@ -346,7 +349,7 @@ class CombineAssets $actionExists = Route::getRoutes()->getByAction($combineAction) !== null; if ($actionExists) { - return URL::action($combineAction, [$outputFilename], false); + return Url::action($combineAction, [$outputFilename], false); } else { return '/combine/'.$outputFilename; @@ -465,6 +468,29 @@ class CombineAssets } } + /** + * Preprocess filters to use standard configuration provided by the system. + * @param array $filters + * @return array + */ + protected function processFilters($filters) + { + $theme = Theme::getActiveTheme(); + if (!$theme->hasCustomData()) { + return $filters; + } + + $assetVars = $theme->getCustomData()->getAssetVariables(); + + foreach ($filters as $filter) { + if (method_exists($filter, 'setPresets')) { + $filter->setPresets($assetVars); + } + } + + return $filters; + } + // // Bundles // @@ -651,17 +677,17 @@ class CombineAssets */ public static function resetCache() { - if (!Cache::has('combiner.index')) { - return; + if (Cache::has('combiner.index')) { + $index = (array) @unserialize(@base64_decode(Cache::get('combiner.index'))) ?: []; + + foreach ($index as $cacheId) { + Cache::forget($cacheId); + } + + Cache::forget('combiner.index'); } - $index = (array) @unserialize(@base64_decode(Cache::get('combiner.index'))) ?: []; - - foreach ($index as $cacheId) { - Cache::forget($cacheId); - } - - Cache::forget('combiner.index'); + CacheHelper::instance()->clearCombiner(); } /**