/** * Sets the active theme. * The active theme code is stored in the database and overrides the configuration cms.activeTheme parameter. * @param string $code Specifies the active theme code. */ public static function setActiveTheme($code) { self::$activeThemeCache = false; self::$editThemeCache = false; $paramKey = 'cms::theme.active'; Parameters::set($paramKey, $code); Cache::forget($paramKey); }
/** * Resets any memory or cache involved with the active or edit theme. * @return void */ public static function resetCache() { self::$activeThemeCache = false; self::$editThemeCache = false; Cache::forget(self::ACTIVE_KEY); Cache::forget(self::EDIT_KEY); }
/** * 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 = Cache::remember(self::ACTIVE_KEY, 1440, function () { return Parameters::applyKey(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; }