Skip to content

Commit

Permalink
Add cms.theme.setActiveTheme event
Browse files Browse the repository at this point in the history
Bring other event names in to line with convention
Complete getConfigArray method
  • Loading branch information
daftspunk committed Mar 23, 2016
1 parent 484579a commit 7c08b10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
30 changes: 22 additions & 8 deletions modules/cms/classes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function isActiveTheme()
/**
* 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.
*/
Expand All @@ -157,7 +157,7 @@ public static function getActiveThemeCode()
}
}

$apiResult = Event::fire('cms.activeTheme', [], true);
$apiResult = Event::fire('cms.theme.getActiveTheme', [], true);
if ($apiResult !== null) {
$activeTheme = $apiResult;
}
Expand All @@ -171,9 +171,7 @@ public static function getActiveThemeCode()


/**
* 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.
*/
Expand All @@ -200,13 +198,16 @@ public static function getActiveTheme()
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
Expand All @@ -218,7 +219,7 @@ public static function getEditThemeCode()
$editTheme = static::getActiveThemeCode();
}

$apiResult = Event::fire('cms.editTheme', [], true);
$apiResult = Event::fire('cms.theme.getEditTheme', [], true);
if ($apiResult !== null) {
$editTheme = $apiResult;
}
Expand Down Expand Up @@ -313,7 +314,20 @@ public function getConfigArray($name)
$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;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/cms/classes/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function setUp()
parent::setUp();

Config::set('cms.activeTheme', 'test');
Event::flush('cms.activeTheme');
Event::flush('cms.theme.getActiveTheme');
Theme::resetCache();
}

Expand Down Expand Up @@ -74,8 +74,8 @@ public function testNoActiveTheme()

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);
Expand Down

0 comments on commit 7c08b10

Please sign in to comment.