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:
Ingo Schommer 2010-04-13 03:18:10 +00:00
parent ee1fda176b
commit 0a4d5ca990
3 changed files with 16 additions and 21 deletions

View File

@ -87,11 +87,6 @@ class SSViewer {
*/ */
protected static $current_theme = null; protected static $current_theme = null;
/**
* @var string
*/
protected static $cached_theme = null;
/** /**
* Create a template from a string instead of a .ss file * Create a template from a string instead of a .ss file
* *
@ -111,18 +106,8 @@ class SSViewer {
/** /**
* @return string * @return string
*/ */
static function current_theme($cached = true) { static function current_theme() {
if($cached && self::$cached_theme) { return self::$current_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;
} }
/** /**
@ -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; $this->content = $content;
} }
public function process($item) { public function process($item, $cache = null) {
$template = SSViewer::parseTemplateContent($this->content, "string sha1=".sha1($this->content)); $template = SSViewer::parseTemplateContent($this->content, "string sha1=".sha1($this->content));
$tmpFile = tempnam(TEMP_FOLDER,""); $tmpFile = tempnam(TEMP_FOLDER,"");

View File

@ -122,6 +122,10 @@ class ContentController extends Controller {
} }
} }
// Use theme from the site config
if(($config = SiteConfig::current_site_config()) && $config->Theme) {
SSViewer::set_theme($config->Theme);
}
} }
/** /**

View File

@ -18,6 +18,11 @@ class SSViewerTest extends SapphireTest {
$config->Theme = 'myusertheme'; $config->Theme = 'myusertheme';
$config->write(); $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'); $this->assertEquals('myusertheme', SSViewer::current_theme(), 'Current theme is a user defined one');
// Set the theme back to the original // Set the theme back to the original