API Replaced SSViewer.custom_theme with SSViewer.theme_enabled

Since we can't influence the setting of configuration values,
we also can't set/unset the 'custom_theme' value based on which
theme is set. This means the 'custom_theme' value goes stale,
and we can't rely on it e.g. in FilesystemPublisher.

The 'theme_enabled' toggle is a cleaner solution to the same problem,
since the 'custom_theme' was really just a way to remember the original
theme, while still disabling it. The toggle makes this more explicit,
but also requires users of the 'theme' setting to check for it.
This commit is contained in:
Ingo Schommer 2013-03-27 10:13:24 +01:00
parent e2b42ca4c2
commit 828ac7fe4f
4 changed files with 35 additions and 18 deletions

View File

@ -266,7 +266,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
// Use theme from the site config
if(class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) {
$theme = $config->Theme;
} elseif(Config::inst()->get('SSViewer', 'theme')) {
} elseif(Config::inst()->get('SSViewer', 'theme_enabled') && Config::inst()->get('SSViewer', 'theme')) {
$theme = Config::inst()->get('SSViewer', 'theme');
} else {
$theme = false;
@ -387,9 +387,8 @@ class LeftAndMain extends Controller implements PermissionProvider {
$dummy = null;
$this->extend('init', $dummy);
// The user's theme shouldn't affect the CMS, if, for example, they have replaced
// TableListField.ss or Form.ss.
Config::inst()->update('SSViewer', 'theme', null);
// The user's theme shouldn't affect the CMS, if, for example, they have replaced TableListField.ss or Form.ss.
Config::inst()->update('SSViewer', 'theme_enabled', false);
}
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {

View File

@ -427,4 +427,7 @@ you can enable those warnings and future-proof your code already.
`YearlyTask` are deprecated, please extend from `BuildTask` or `CliController`,
and invoke them in self-defined frequencies through Unix cronjobs etc.
* `i18n::$common_locales` and `i18n::$common_languages` are now accessed via the Config API, and contain associative rather than indexed arrays.
Before: `array('de_DE' => array('German', 'Deutsch'))`, after: `array('de_DE' => array('name' => 'German', 'native' => 'Deutsch'))`.
Before: `array('de_DE' => array('German', 'Deutsch'))`, after: `array('de_DE' => array('name' => 'German', 'native' => 'Deutsch'))`.
* `SSViewer::current_custom_theme()` has been replaced with the `SSViewer.theme_enabled` configuration setting.
Please use it to toggle theme behaviour rather than relying on the custom theme being set in the
(now deprecated) `SSViewer::set_theme()` call.

View File

@ -572,15 +572,20 @@ class SSViewer {
/**
* @config
* @var string
* @var string The used "theme", which usually consists of templates, images and stylesheets.
* Only used when {@link $theme_enabled} is set to TRUE.
*/
private static $current_theme = null;
private static $theme = null;
/**
* @config
* @var string
* @var string Use the theme. Set to FALSE in order to disable themes,
* which can be useful for scenarios where theme overrides are temporarily undesired,
* such as an administrative interface separate from the website theme.
* It retains the theme settings to be re-enabled, for example when a website content
* needs to be rendered from within this administrative interface.
*/
private static $current_custom_theme = null;
private static $theme_enabled = true;
/**
* @var boolean
@ -603,9 +608,6 @@ class SSViewer {
public static function set_theme($theme) {
Deprecation::notice('3.2', 'Use the "SSViewer.theme" config setting instead');
Config::inst()->update('SSViewer', 'theme', $theme);
//Static publishing needs to have a theme set, otherwise it defaults to the content controller theme
if(!is_null($theme))
Config::inst()->update('SSViewer', 'custom_theme', $theme);
}
/**
@ -655,8 +657,8 @@ class SSViewer {
* @return string
*/
public static function current_custom_theme(){
Deprecation::notice('3.2', 'Use the "SSViewer.theme" config setting instead');
return Config::inst()->get('SSViewer', 'custom_theme');
Deprecation::notice('3.2', 'Use the "SSViewer.theme" and "SSViewer.theme_enabled" config settings instead');
return Config::inst()->get('SSViewer', 'theme_enabled') ? Config::inst()->get('SSViewer', 'theme') : null;
}
/**
@ -683,8 +685,13 @@ class SSViewer {
if(!is_array($templateList) && substr((string) $templateList,-3) == '.ss') {
$this->chosenTemplates['main'] = $templateList;
} else {
if(Config::inst()->get('SSViewer', 'theme_enabled')) {
$theme = Config::inst()->get('SSViewer', 'theme');
} else {
$theme = null;
}
$this->chosenTemplates = SS_TemplateLoader::instance()->findTemplates(
$templateList, Config::inst()->get('SSViewer', 'theme')
$templateList, $theme
);
}
@ -792,7 +799,12 @@ class SSViewer {
*/
public static function getTemplateFileByType($identifier, $type) {
$loader = SS_TemplateLoader::instance();
$found = $loader->findTemplates("$type/$identifier", Config::inst()->get('SSViewer', 'theme'));
if(Config::inst()->get('SSViewer', 'theme_enabled')) {
$theme = Config::inst()->get('SSViewer', 'theme');
} else {
$theme = null;
}
$found = $loader->findTemplates("$type/$identifier", $theme);
if ($found) {
return $found['main'];

View File

@ -522,7 +522,10 @@ class ViewableData extends Object implements IteratorAggregate {
* @return string
*/
public function ThemeDir($subtheme = false) {
if($theme = Config::inst()->get('SSViewer', 'theme')) {
if(
Config::inst()->get('SSViewer', 'theme_enabled')
&& $theme = Config::inst()->get('SSViewer', 'theme')
) {
return THEMES_DIR . "/$theme" . ($subtheme ? "_$subtheme" : null);
}