Add cms.theme.setActiveTheme event
Bring other event names in to line with convention Complete getConfigArray method
This commit is contained in:
parent
484579ac40
commit
7c08b10fa2
|
|
@ -139,7 +139,7 @@ class Theme
|
||||||
/**
|
/**
|
||||||
* Returns the active theme code.
|
* Returns the active theme code.
|
||||||
* By default the active theme is loaded from the cms.activeTheme parameter,
|
* 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
|
* @return string
|
||||||
* If the theme doesn't exist, returns null.
|
* 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) {
|
if ($apiResult !== null) {
|
||||||
$activeTheme = $apiResult;
|
$activeTheme = $apiResult;
|
||||||
}
|
}
|
||||||
|
|
@ -171,9 +171,7 @@ class Theme
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the active theme.
|
* Returns the active theme object.
|
||||||
* By default the active theme is loaded from the cms.activeTheme parameter,
|
|
||||||
* but this behavior can be overridden by the cms.activeTheme event listeners.
|
|
||||||
* @return \Cms\Classes\Theme Returns the loaded theme object.
|
* @return \Cms\Classes\Theme Returns the loaded theme object.
|
||||||
* If the theme doesn't exist, returns null.
|
* If the theme doesn't exist, returns null.
|
||||||
*/
|
*/
|
||||||
|
|
@ -200,13 +198,16 @@ class Theme
|
||||||
public static function setActiveTheme($code)
|
public static function setActiveTheme($code)
|
||||||
{
|
{
|
||||||
self::resetCache();
|
self::resetCache();
|
||||||
|
|
||||||
Parameters::set(self::ACTIVE_KEY, $code);
|
Parameters::set(self::ACTIVE_KEY, $code);
|
||||||
|
|
||||||
|
Event::fire('cms.theme.setActiveTheme', compact('code'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the edit theme code.
|
* Returns the edit theme code.
|
||||||
* By default the edit theme is loaded from the cms.editTheme parameter,
|
* 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
|
* If the edit theme is not defined in the configuration file, the active theme
|
||||||
* is returned.
|
* is returned.
|
||||||
* @return string
|
* @return string
|
||||||
|
|
@ -218,7 +219,7 @@ class Theme
|
||||||
$editTheme = static::getActiveThemeCode();
|
$editTheme = static::getActiveThemeCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiResult = Event::fire('cms.editTheme', [], true);
|
$apiResult = Event::fire('cms.theme.getEditTheme', [], true);
|
||||||
if ($apiResult !== null) {
|
if ($apiResult !== null) {
|
||||||
$editTheme = $apiResult;
|
$editTheme = $apiResult;
|
||||||
}
|
}
|
||||||
|
|
@ -313,7 +314,20 @@ class Theme
|
||||||
$result = array_get($this->getConfig(), $name, []);
|
$result = array_get($this->getConfig(), $name, []);
|
||||||
|
|
||||||
if (is_string($result)) {
|
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;
|
return (array) $result;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class ThemeTest extends TestCase
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Config::set('cms.activeTheme', 'test');
|
Config::set('cms.activeTheme', 'test');
|
||||||
Event::flush('cms.activeTheme');
|
Event::flush('cms.theme.getActiveTheme');
|
||||||
Theme::resetCache();
|
Theme::resetCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,8 +74,8 @@ class ThemeTest extends TestCase
|
||||||
|
|
||||||
public function testApiTheme()
|
public function testApiTheme()
|
||||||
{
|
{
|
||||||
Event::flush('cms.activeTheme');
|
Event::flush('cms.theme.getActiveTheme');
|
||||||
Event::listen('cms.activeTheme', function() { return 'apitest'; });
|
Event::listen('cms.theme.getActiveTheme', function() { return 'apitest'; });
|
||||||
|
|
||||||
$activeTheme = Theme::getActiveTheme();
|
$activeTheme = Theme::getActiveTheme();
|
||||||
$this->assertNotNull($activeTheme);
|
$this->assertNotNull($activeTheme);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue