BUGFIX: Updated SiteConfig-based theme selection to remove inappropriate coupling from SSViewer

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98263 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-02-05 00:02:50 +00:00
parent a66d3045fc
commit 60f93644a0
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);
} }
/** /**
@ -637,7 +623,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

@ -119,8 +119,12 @@ class ContentController extends Controller {
return Security::permissionFailure($this, sprintf($message, "$link?stage=Live")); 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);
}
} }
/** /**

View File

@ -12,12 +12,17 @@ class SSViewerTest extends SapphireTest {
$oldTheme = $config->Theme; $oldTheme = $config->Theme;
$config->Theme = ''; $config->Theme = '';
$config->write(); $config->write();
SSViewer::set_theme('mytheme'); SSViewer::set_theme('mytheme');
$this->assertEquals('mytheme', SSViewer::current_theme(), 'Current theme is the default - user has not defined one'); $this->assertEquals('mytheme', SSViewer::current_theme(), 'Current theme is the default - user has not defined one');
$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