From 7c08b10fa2f509124a7b9de6bbd8468be308bf46 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 23 Mar 2016 20:11:55 +1100 Subject: [PATCH] Add cms.theme.setActiveTheme event Bring other event names in to line with convention Complete getConfigArray method --- modules/cms/classes/Theme.php | 30 ++++++++++++++++++++-------- tests/unit/cms/classes/ThemeTest.php | 6 +++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index 7f84c4d7d..88ab64f6d 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -139,7 +139,7 @@ class Theme /** * Returns the active theme code. * By default the active theme is loaded from the cms.activeTheme parameter, - * but this behavior can be overridden by the cms.activeTheme event listeners. + * but this behavior can be overridden by the cms.theme.getActiveTheme event listeners. * @return string * If the theme doesn't exist, returns null. */ @@ -157,7 +157,7 @@ class Theme } } - $apiResult = Event::fire('cms.activeTheme', [], true); + $apiResult = Event::fire('cms.theme.getActiveTheme', [], true); if ($apiResult !== null) { $activeTheme = $apiResult; } @@ -171,9 +171,7 @@ class Theme /** - * Returns the active theme. - * By default the active theme is loaded from the cms.activeTheme parameter, - * but this behavior can be overridden by the cms.activeTheme event listeners. + * Returns the active theme object. * @return \Cms\Classes\Theme Returns the loaded theme object. * If the theme doesn't exist, returns null. */ @@ -200,13 +198,16 @@ class Theme public static function setActiveTheme($code) { self::resetCache(); + Parameters::set(self::ACTIVE_KEY, $code); + + Event::fire('cms.theme.setActiveTheme', compact('code')); } /** * Returns the edit theme code. * By default the edit theme is loaded from the cms.editTheme parameter, - * but this behavior can be overridden by the cms.editTheme event listeners. + * but this behavior can be overridden by the cms.theme.getEditTheme event listeners. * If the edit theme is not defined in the configuration file, the active theme * is returned. * @return string @@ -218,7 +219,7 @@ class Theme $editTheme = static::getActiveThemeCode(); } - $apiResult = Event::fire('cms.editTheme', [], true); + $apiResult = Event::fire('cms.theme.getEditTheme', [], true); if ($apiResult !== null) { $editTheme = $apiResult; } @@ -313,7 +314,20 @@ class Theme $result = array_get($this->getConfig(), $name, []); if (is_string($result)) { - // Load from file + $fileName = File::symbolizePath($result); + + if (File::isLocalPath($fileName) || realpath($fileName) !== false) { + $path = $fileName; + } + else { + $path = $this->getPath().'/'.$result; + } + + if (!File::exists($path)) { + throw new ApplicationException('Path does not exist: '.$path); + } + + $result = Yaml::parseFile($path); } return (array) $result; diff --git a/tests/unit/cms/classes/ThemeTest.php b/tests/unit/cms/classes/ThemeTest.php index c9e2368e6..22e18eeb0 100644 --- a/tests/unit/cms/classes/ThemeTest.php +++ b/tests/unit/cms/classes/ThemeTest.php @@ -9,7 +9,7 @@ class ThemeTest extends TestCase parent::setUp(); Config::set('cms.activeTheme', 'test'); - Event::flush('cms.activeTheme'); + Event::flush('cms.theme.getActiveTheme'); Theme::resetCache(); } @@ -74,8 +74,8 @@ class ThemeTest extends TestCase public function testApiTheme() { - Event::flush('cms.activeTheme'); - Event::listen('cms.activeTheme', function() { return 'apitest'; }); + Event::flush('cms.theme.getActiveTheme'); + Event::listen('cms.theme.getActiveTheme', function() { return 'apitest'; }); $activeTheme = Theme::getActiveTheme(); $this->assertNotNull($activeTheme);