/** * 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. * @return \Cms\Classes\Theme Returns the loaded theme object. * If the theme doesn't exist, returns null. */ public static function getActiveTheme() { $paramKey = 'cms::theme.active'; $activeTheme = Config::get('cms.activeTheme'); if (DbDongle::hasDatabase()) { $dbResult = Parameters::findRecord($paramKey)->remember(1440, $paramKey)->pluck('value'); if ($dbResult !== null) { $activeTheme = $dbResult; } } $apiResult = Event::fire('cms.activeTheme', [], true); if ($apiResult !== null) { $activeTheme = $apiResult; } if (!strlen($activeTheme)) { throw new SystemException(Lang::get('cms::lang.theme.active.not_set')); } $theme = new static(); $theme->load($activeTheme); if (!File::isDirectory($theme->getPath())) { return null; } return $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. * @return \Cms\Classes\Theme Returns the loaded theme object. * If the theme doesn't exist, returns null. */ public static function getActiveTheme() { if (self::$activeThemeCache !== false) { return self::$activeThemeCache; } $activeTheme = Config::get('cms.activeTheme'); if (DbDongle::hasDatabase()) { $dbResult = Parameters::findRecord(self::ACTIVE_KEY)->remember(1440, self::ACTIVE_KEY)->pluck('value'); if ($dbResult !== null && static::exists($dbResult)) { $activeTheme = $dbResult; } } $apiResult = Event::fire('cms.activeTheme', [], true); if ($apiResult !== null) { $activeTheme = $apiResult; } if (!strlen($activeTheme)) { throw new SystemException(Lang::get('cms::lang.theme.active.not_set')); } $theme = static::load($activeTheme); if (!File::isDirectory($theme->getPath())) { return self::$activeThemeCache = null; } return self::$activeThemeCache = $theme; }