Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 828ac7fe4f2e54319dca0159b3a94f5d19729ac6 1 parent e2b42ca
@chillu chillu authored
View
7 admin/code/LeftAndMain.php
@@ -266,7 +266,7 @@ public function init() {
// 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 @@ public function init() {
$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
5 docs/en/changelogs/3.1.0.md
@@ -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
36 view/SSViewer.php
@@ -572,15 +572,20 @@ public static function get_source_file_comments() {
/**
* @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 @@ public static function fromString($content) {
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 @@ public static function get_themes($path = null, $subthemes = false) {
* @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 @@ public function __construct($templateList) {
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 @@ public function exists() {
*/
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
5 view/ViewableData.php
@@ -522,7 +522,10 @@ public function Me() {
* @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);
}

0 comments on commit 828ac7f

Please sign in to comment.
Something went wrong with that request. Please try again.