mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Updated SiteConfig-based theme selection to remove inappropriate coupling from SSViewer (from r98263)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102636 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ee1fda176b
commit
0a4d5ca990
@ -87,11 +87,6 @@ class SSViewer {
|
||||
*/
|
||||
protected static $current_theme = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected static $cached_theme = null;
|
||||
|
||||
/**
|
||||
* Create a template from a string instead of a .ss file
|
||||
*
|
||||
@ -111,18 +106,8 @@ class SSViewer {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static function current_theme($cached = true) {
|
||||
if($cached && self::$cached_theme) {
|
||||
// First case is to return the cached user theme so we don't requery SiteConfig again
|
||||
return self::$cached_theme;
|
||||
} else {
|
||||
// Need to refresh the cache from the SiteConfig
|
||||
$theme = SiteConfig::current_site_config()->Theme;
|
||||
self::$cached_theme = $theme;
|
||||
}
|
||||
// Fall back to the default SSViewer::set_theme() behaviour
|
||||
if(!$theme) $theme = self::$current_theme;
|
||||
return $theme;
|
||||
static function current_theme() {
|
||||
return self::$current_theme;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +172,8 @@ class SSViewer {
|
||||
|
||||
}
|
||||
|
||||
if(!$this->chosenTemplates) user_error("None of these templates can be found: ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING);
|
||||
if(!$this->chosenTemplates) user_error("None of these templates can be found in theme '"
|
||||
. self::current_theme() . "': ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -642,7 +628,7 @@ class SSViewer_FromString extends SSViewer {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function process($item) {
|
||||
public function process($item, $cache = null) {
|
||||
$template = SSViewer::parseTemplateContent($this->content, "string sha1=".sha1($this->content));
|
||||
|
||||
$tmpFile = tempnam(TEMP_FOLDER,"");
|
||||
|
@ -120,8 +120,12 @@ class ContentController extends Controller {
|
||||
|
||||
return Security::permissionFailure($this, sprintf($message, "$link?stage=Live"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use theme from the site config
|
||||
if(($config = SiteConfig::current_site_config()) && $config->Theme) {
|
||||
SSViewer::set_theme($config->Theme);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,12 +12,17 @@ class SSViewerTest extends SapphireTest {
|
||||
$oldTheme = $config->Theme;
|
||||
$config->Theme = '';
|
||||
$config->write();
|
||||
|
||||
|
||||
SSViewer::set_theme('mytheme');
|
||||
$this->assertEquals('mytheme', SSViewer::current_theme(), 'Current theme is the default - user has not defined one');
|
||||
|
||||
$config->Theme = 'myusertheme';
|
||||
$config->write();
|
||||
|
||||
// Pretent to load the page
|
||||
$c = new ContentController();
|
||||
$c->init();
|
||||
|
||||
$this->assertEquals('myusertheme', SSViewer::current_theme(), 'Current theme is a user defined one');
|
||||
|
||||
// Set the theme back to the original
|
||||
|
Loading…
Reference in New Issue
Block a user