There are no theme options available to customize.
+diff --git a/modules/cms/controllers/ThemeOptions.php b/modules/cms/controllers/ThemeOptions.php new file mode 100644 index 000000000..a9d499fcb --- /dev/null +++ b/modules/cms/controllers/ThemeOptions.php @@ -0,0 +1,142 @@ +pageTitle = 'cms::lang.theme.settings_menu'; + + BackendMenu::setContext('October.System', 'system', 'settings'); + SettingsManager::setContext('October.Cms', 'theme'); + } + + public function update($dirName = null) + { + /* + * Only the active theme can be managed without this permission + */ + if ($dirName && !$this->user->hasAccess('cms.manage_themes')) { + $dirName = null; + } + + if ($dirName === null) { + $dirName = CmsTheme::getActiveThemeCode(); + } + + try { + $model = $this->getThemeData($dirName); + + $this->asExtension('FormController')->update($model->id); + + $this->vars['hasCustomData'] = $this->hasThemeData($dirName); + } + catch (Exception $ex) { + $this->handleError($ex); + } + } + + public function update_onSave($dirName) + { + $model = $this->getThemeData($dirName); + $this->asExtension('FormController')->update_onSave($model->id); + } + + public function update_onResetDefault($dirName) + { + $model = $this->getThemeData($dirName); + $model->delete(); + + return Backend::redirect('cms/themeoptions/update/'.$dirName); + } + + protected function hasThemeData($dirName) + { + return $this->findThemeObject($dirName)->hasCustomData(); + } + + protected function getThemeData($dirName) + { + $theme = $this->findThemeObject($dirName); + $model = ThemeData::forTheme($theme); + return $model; + } + + /** + * Add form fields defined in theme.yaml + */ + public function formExtendFields($form) + { + $model = $form->model; + $theme = $this->findThemeObject($model->theme); + $config = $theme->getConfigArray('form'); + + if ($fields = array_get($config, 'fields')) { + $form->addFields($fields); + } + + if ($fields = array_get($config, 'tabs.fields')) { + $form->addTabFields($fields); + } + + if ($fields = array_get($config, 'secondaryTabs.fields')) { + $form->addSecondaryTabFields($fields); + } + } + + // + // Helpers + // + + protected function findThemeObject($name = null) + { + if ($name === null) { + $name = post('theme'); + } + + if (!$name || (!$theme = CmsTheme::load($name))) { + throw new ApplicationException(trans('cms::lang.theme.not_found_name', ['name' => $name])); + } + + return $theme; + } +} diff --git a/modules/cms/controllers/Themes.php b/modules/cms/controllers/Themes.php index 629b16b5c..d2fec58f4 100644 --- a/modules/cms/controllers/Themes.php +++ b/modules/cms/controllers/Themes.php @@ -2,12 +2,10 @@ use File; use Yaml; -use View; use Flash; use Config; use Backend; use Redirect; -use Response; use BackendMenu; use ValidationException; use ApplicationException; @@ -29,13 +27,7 @@ use Exception; */ class Themes extends Controller { - public $implement = [ - 'Backend.Behaviors.FormController' - ]; - - public $formConfig = 'config_form.yaml'; - - public $requiredPermissions = ['cms.manage_themes', 'cms.manage_theme_options']; + public $requiredPermissions = ['cms.manage_themes']; /** * Constructor. @@ -50,6 +42,15 @@ class Themes extends Controller BackendMenu::setContext('October.System', 'system', 'settings'); SettingsManager::setContext('October.Cms', 'theme'); + /* + * Custom redirect for unauthorized request + */ + $this->bindEvent('page.beforeDisplay', function() { + if (!$this->user->hasAnyAccess($this->requiredPermissions)) { + return Backend::redirect('cms/themeoptions/update'); + } + }); + /* * Enable AJAX for Form widgets */ @@ -58,43 +59,6 @@ class Themes extends Controller } } - /** - * Check user's permissions - */ - public function run($action = null, $params = []) - { - $canAccess = false; - $user = \BackendAuth::getUser(); - - if (!$user->hasAccess('cms.manage_themes')) { - $activeThemeCode = CmsTheme::getActiveThemeCode(); - - switch ($action) { - case 'update': - if ( - $user->hasAccess('cms.manage_theme_options') && - @$params[0] === $activeThemeCode - ) { - $canAccess = true; - } - break; - default: - if ($user->hasAccess('cms.manage_theme_options')) { - return Redirect::to(Backend::url("cms/themes/update/$activeThemeCode")); - } - break; - } - } else { - $canAccess = true; - } - - if ($canAccess) { - return parent::run($action, $params); - } else { - return Response::make(View::make('backend::access_denied'), 403); - } - } - public function index() { $this->bodyClass = 'compact-container'; @@ -247,64 +211,6 @@ class Themes extends Controller return Redirect::refresh(); } - // - // Theme customization - // - - public function update($dirName) - { - try { - $model = $this->getThemeData($dirName); - $this->asExtension('FormController')->update($model->id); - } - catch (Exception $ex) { - $this->handleError($ex); - } - } - - public function update_onSave($dirName) - { - $model = $this->getThemeData($dirName); - $this->asExtension('FormController')->update_onSave($model->id); - } - - public function update_onResetDefault($dirName) - { - $model = $this->getThemeData($dirName); - $model->delete(); - - return Backend::redirect('cms/themes/update/'.$dirName); - } - - protected function getThemeData($dirName) - { - $theme = $this->findThemeObject($dirName); - $model = ThemeData::forTheme($theme); - return $model; - } - - /** - * Add form fields defined in theme.yaml - */ - public function formExtendFields($form) - { - $model = $form->model; - $theme = $this->findThemeObject($model->theme); - $config = $theme->getConfigArray('form'); - - if ($fields = array_get($config, 'fields')) { - $form->addFields($fields); - } - - if ($fields = array_get($config, 'tabs.fields')) { - $form->addTabFields($fields); - } - - if ($fields = array_get($config, 'secondaryTabs.fields')) { - $form->addSecondaryTabFields($fields); - } - } - // // Theme export // @@ -405,5 +311,4 @@ class Themes extends Controller return $theme; } - } diff --git a/modules/cms/controllers/themes/config_form.yaml b/modules/cms/controllers/themeoptions/config_form.yaml similarity index 100% rename from modules/cms/controllers/themes/config_form.yaml rename to modules/cms/controllers/themeoptions/config_form.yaml diff --git a/modules/cms/controllers/themeoptions/update.htm b/modules/cms/controllers/themeoptions/update.htm new file mode 100644 index 000000000..341360910 --- /dev/null +++ b/modules/cms/controllers/themeoptions/update.htm @@ -0,0 +1,68 @@ + +
There are no theme options available to customize.
+= e(trans('cms::lang.theme.return')) ?>
+ + diff --git a/modules/cms/controllers/themes/_theme_list_item.htm b/modules/cms/controllers/themes/_theme_list_item.htm index 1ef44053b..206d30a0d 100644 --- a/modules/cms/controllers/themes/_theme_list_item.htm +++ b/modules/cms/controllers/themes/_theme_list_item.htm @@ -36,7 +36,7 @@ hasCustomData()): ?> = e(trans('cms::lang.theme.customize_button')) ?> diff --git a/modules/cms/controllers/themes/update.htm b/modules/cms/controllers/themes/update.htm deleted file mode 100644 index 0f222d10b..000000000 --- a/modules/cms/controllers/themes/update.htm +++ /dev/null @@ -1,59 +0,0 @@ - -= e(trans('cms::lang.theme.return')) ?>
- - \ No newline at end of file diff --git a/modules/cms/lang/en/lang.php b/modules/cms/lang/en/lang.php index d1c7007c5..547661cdd 100644 --- a/modules/cms/lang/en/lang.php +++ b/modules/cms/lang/en/lang.php @@ -35,7 +35,7 @@ return [ 'not_match' => "The object you're trying to access doesn't belong to the theme being edited. Please reload the page." ], 'settings_menu' => 'Front-end theme', - 'settings_menu_description' => 'Manage the front-end theme', + 'settings_menu_description' => 'Manage the front-end theme and customization options.', 'default_tab' => 'Properties', 'name_label' => 'Name', 'name_create_placeholder' => 'New theme name', diff --git a/modules/cms/reportwidgets/activetheme/partials/_widget.htm b/modules/cms/reportwidgets/activetheme/partials/_widget.htm index 9f617bbeb..ca48aa5a6 100644 --- a/modules/cms/reportwidgets/activetheme/partials/_widget.htm +++ b/modules/cms/reportwidgets/activetheme/partials/_widget.htm @@ -28,7 +28,7 @@ hasCustomData()): ?>