Add cms.theme.setActiveTheme event

Bring other event names in to line with convention
Complete getConfigArray method
This commit is contained in:
Samuel Georges 2016-03-23 20:11:55 +11:00
parent 484579ac40
commit 7c08b10fa2
2 changed files with 25 additions and 11 deletions

View File

@ -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;

View File

@ -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);