2014-07-19 02:05:50 +00:00
|
|
|
<?php namespace Cms\Controllers;
|
|
|
|
|
|
2015-03-14 07:09:54 +00:00
|
|
|
use Yaml;
|
2014-07-19 02:05:50 +00:00
|
|
|
use Config;
|
2014-12-04 06:41:07 +00:00
|
|
|
use Backend;
|
|
|
|
|
use Redirect;
|
2014-07-19 02:05:50 +00:00
|
|
|
use BackendMenu;
|
2015-03-14 07:09:54 +00:00
|
|
|
use ApplicationException;
|
2014-12-04 06:41:07 +00:00
|
|
|
use Cms\Models\ThemeData;
|
2015-03-14 07:09:54 +00:00
|
|
|
use Backend\Classes\Controller;
|
2014-07-19 02:05:50 +00:00
|
|
|
use Cms\Classes\Theme as CmsTheme;
|
2015-03-14 07:09:54 +00:00
|
|
|
use System\Classes\SettingsManager;
|
2014-12-04 06:41:07 +00:00
|
|
|
use Exception;
|
2014-07-19 02:05:50 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Theme selector controller
|
|
|
|
|
*
|
|
|
|
|
* @package october\backend
|
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
|
*
|
|
|
|
|
*/
|
2014-07-19 06:14:46 +00:00
|
|
|
class Themes extends Controller
|
2014-07-19 02:05:50 +00:00
|
|
|
{
|
2014-12-04 06:41:07 +00:00
|
|
|
public $implement = [
|
|
|
|
|
'Backend.Behaviors.FormController'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public $formConfig = 'config_form.yaml';
|
2014-07-19 02:05:50 +00:00
|
|
|
|
2014-12-04 06:41:07 +00:00
|
|
|
public $requiredPermissions = ['cms.manage_themes'];
|
2014-07-19 02:05:50 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
|
|
$this->addCss('/modules/cms/assets/css/october.theme-selector.css', 'core');
|
|
|
|
|
|
2014-10-15 08:53:44 +00:00
|
|
|
$this->pageTitle = 'cms::lang.theme.settings_menu';
|
2014-07-19 02:05:50 +00:00
|
|
|
BackendMenu::setContext('October.System', 'system', 'settings');
|
2014-07-24 04:19:00 +00:00
|
|
|
SettingsManager::setContext('October.Cms', 'theme');
|
2014-07-19 02:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2014-12-04 06:41:07 +00:00
|
|
|
$this->bodyClass = 'compact-container';
|
2014-07-19 02:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index_onSetActiveTheme()
|
|
|
|
|
{
|
2015-03-14 07:09:54 +00:00
|
|
|
CmsTheme::setActiveTheme(post('theme'));
|
2014-07-19 02:05:50 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'#theme-list' => $this->makePartial('theme_list')
|
|
|
|
|
];
|
|
|
|
|
}
|
2014-12-04 06:41:07 +00:00
|
|
|
|
2015-03-14 07:09:54 +00:00
|
|
|
//
|
|
|
|
|
// Theme properties
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
public function index_onLoadThemeFieldsForm()
|
|
|
|
|
{
|
|
|
|
|
$theme = $this->findThemeObject();
|
|
|
|
|
$this->vars['widget'] = $this->makeThemeFieldsFormWidget($theme);
|
|
|
|
|
$this->vars['themeDir'] = $theme->getDirName();
|
|
|
|
|
|
|
|
|
|
return $this->makePartial('theme_fields_form');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index_onSaveThemeFields()
|
|
|
|
|
{
|
|
|
|
|
$theme = $this->findThemeObject();
|
|
|
|
|
$widget = $this->makeThemeFieldsFormWidget($theme);
|
|
|
|
|
$theme->writeConfig($widget->getSaveData());
|
|
|
|
|
|
|
|
|
|
return ['#themeListItem-'.$theme->getId() => $this->makePartial('theme_list_item', ['theme' => $theme])];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function makeThemeFieldsFormWidget($theme)
|
|
|
|
|
{
|
|
|
|
|
$widgetConfig = $this->makeConfig('~/modules/cms/classes/theme/fields.yaml');
|
|
|
|
|
$widgetConfig->alias = 'form'.studly_case($theme->getDirName());
|
|
|
|
|
$widgetConfig->model = $theme;
|
|
|
|
|
$widgetConfig->data = $theme->getConfig();
|
|
|
|
|
$widgetConfig->data['directory_name'] = $theme->getDirName();
|
|
|
|
|
$widgetConfig->arrayName = 'Theme';
|
|
|
|
|
|
|
|
|
|
$widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig);
|
|
|
|
|
return $widget;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 06:41:07 +00:00
|
|
|
//
|
|
|
|
|
// 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();
|
|
|
|
|
|
2015-02-11 07:35:39 +00:00
|
|
|
return Backend::redirect('cms/themes/update/'.$dirName);
|
2014-12-04 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getThemeData($dirName)
|
|
|
|
|
{
|
2015-03-14 07:09:54 +00:00
|
|
|
$theme = $this->findThemeObject($dirName);
|
2014-12-05 07:24:48 +00:00
|
|
|
$model = ThemeData::forTheme($theme);
|
2014-12-04 06:41:07 +00:00
|
|
|
return $model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add form fields defined in theme.yaml
|
|
|
|
|
*/
|
|
|
|
|
protected function formExtendFields($form)
|
|
|
|
|
{
|
|
|
|
|
$model = $form->model;
|
2015-03-14 07:09:54 +00:00
|
|
|
$theme = $this->findThemeObject($model->theme);
|
2014-12-04 06:41:07 +00:00
|
|
|
|
|
|
|
|
if ($fields = $theme->getConfigValue('form.fields')) {
|
|
|
|
|
$form->addFields($fields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($fields = $theme->getConfigValue('form.tabs.fields')) {
|
|
|
|
|
$form->addTabFields($fields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($fields = $theme->getConfigValue('form.secondaryTabs.fields')) {
|
|
|
|
|
$form->addSecondaryTabFields($fields);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 07:09:54 +00:00
|
|
|
//
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 23:27:52 +00:00
|
|
|
}
|