Theme
in package
This class represents the CMS theme.
CMS theme is a directory that contains all CMS objects - pages, layouts, partials and asset files.. The theme parameters are specified in the theme.ini file in the theme root directory.
Tags
Table of Contents
- ACTIVE_KEY = 'cms::theme.active'
- EDIT_KEY = 'cms::theme.edit'
- $activeThemeCache : mixed
- $configCache : mixed
- $dirName : string
- $editThemeCache : mixed
- __get() : void
- Implements the getter functionality.
- __isset() : void
- Determine if an attribute exists on the object.
- all() : array<string|int, mixed>
- Returns a list of all themes.
- databaseLayerEnabled() : bool
- Checks to see if the database layer has been enabled
- exists() : bool
- Determines if a theme with given directory name exists
- getActiveTheme() : Theme
- Returns the active theme object.
- getActiveThemeCode() : string
- Returns the active theme code.
- getConfig() : array<string|int, mixed>
- Reads the theme.yaml file and returns the theme configuration values.
- getConfigArray() : array<string|int, mixed>
- Returns an array value from the theme configuration file by its name.
- getConfigValue() : mixed
- Returns a value from the theme configuration file by its name.
- getCustomData() : ThemeData
- Returns data specific to this theme
- getDatasource() : DatasourceInterface
- Get the theme's datasource
- getDirName() : string
- Returns the theme directory name.
- getEditTheme() : Theme
- Returns the edit theme.
- getEditThemeCode() : string
- Returns the edit theme code.
- getFormConfig() : array<string|int, mixed>
- Themes have a dedicated `form` option that provide form fields for customization, this is an immutable accessor for that and also an solid anchor point for extension.
- getId() : string
- Helper for {{ theme.id }} twig vars Returns a unique string for this theme.
- getPath() : string
- Returns the absolute theme path.
- getPreviewImageUrl() : string
- Returns the theme preview image URL.
- hasCustomData() : bool
- Returns true if this theme has form fields that supply customization data.
- isActiveTheme() : mixed
- Returns true if this theme is the chosen active theme.
- listPages() : array<string|int, mixed>
- Returns a list of pages in the theme.
- load() : self
- Loads the theme.
- registerHalcyonDatasource() : void
- Ensures this theme is registered as a Halcyon datasource.
- removeCustomData() : bool
- Remove data specific to this theme
- resetCache() : void
- Resets any memory or cache involved with the active or edit theme.
- setActiveTheme() : mixed
- Sets the active theme.
- setDirName() : void
- Sets the theme directory name.
- writeConfig() : void
- Writes to the theme.yaml file with the supplied array values.
Constants
ACTIVE_KEY
public
mixed
ACTIVE_KEY
= 'cms::theme.active'
EDIT_KEY
public
mixed
EDIT_KEY
= 'cms::theme.edit'
Properties
$activeThemeCache
protected
static mixed
$activeThemeCache
= false
Active theme cache in memory
$configCache
protected
mixed
$configCache
Keeps the cached configuration file values.
$dirName
protected
string
$dirName
Specifies the theme directory name.
$editThemeCache
protected
static mixed
$editThemeCache
= false
Edit theme cache in memory
Methods
__get()
Implements the getter functionality.
public
__get(string $name) : void
Parameters
- $name : string
Return values
void —__isset()
Determine if an attribute exists on the object.
public
__isset(string $key) : void
Parameters
- $key : string
Return values
void —all()
Returns a list of all themes.
public
static all() : array<string|int, mixed>
Return values
array<string|int, mixed> —Returns an array of the Theme objects.
databaseLayerEnabled()
Checks to see if the database layer has been enabled
public
static databaseLayerEnabled() : bool
Return values
bool —exists()
Determines if a theme with given directory name exists
public
static exists(string $dirName) : bool
Parameters
- $dirName : string
-
The theme directory
Return values
bool —getActiveTheme()
Returns the active theme object.
public
static getActiveTheme() : Theme
Return values
Theme —Returns the loaded theme object. If the theme doesn't exist, returns null.
getActiveThemeCode()
Returns the active theme code.
public
static getActiveThemeCode() : string
By default the active theme is loaded from the cms.activeTheme parameter, but this behavior can be overridden by the cms.theme.getActiveTheme event listener.
Return values
string —If the theme doesn't exist, returns null.
getConfig()
Reads the theme.yaml file and returns the theme configuration values.
public
getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed> —Returns the parsed configuration file values.
getConfigArray()
Returns an array value from the theme configuration file by its name.
public
getConfigArray(string $name) : array<string|int, mixed>
If the value is a string, it is treated as a YAML file and loaded.
Parameters
- $name : string
-
Specifies the configuration parameter name.
Return values
array<string|int, mixed> —getConfigValue()
Returns a value from the theme configuration file by its name.
public
getConfigValue(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
-
Specifies the configuration parameter name.
- $default : mixed = null
-
Specifies the default value to return in case if the parameter doesn't exist in the configuration file.
Return values
mixed —Returns the parameter value or a default value
getCustomData()
Returns data specific to this theme
public
getCustomData() : ThemeData
Return values
ThemeData —getDatasource()
Get the theme's datasource
public
getDatasource() : DatasourceInterface
Return values
DatasourceInterface —getDirName()
Returns the theme directory name.
public
getDirName() : string
Return values
string —getEditTheme()
Returns the edit theme.
public
static getEditTheme() : Theme
Return values
Theme —Returns the loaded theme object.
getEditThemeCode()
Returns the edit theme code.
public
static getEditThemeCode() : string
By default the edit theme is loaded from the cms.editTheme parameter, 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 values
string —getFormConfig()
Themes have a dedicated `form` option that provide form fields for customization, this is an immutable accessor for that and also an solid anchor point for extension.
public
getFormConfig() : array<string|int, mixed>
Return values
array<string|int, mixed> —getId()
Helper for {{ theme.id }} twig vars Returns a unique string for this theme.
public
getId() : string
Return values
string —getPath()
Returns the absolute theme path.
public
getPath([string $dirName = null ]) : string
Parameters
- $dirName : string = null
-
Optional theme directory. Defaults to $this->getDirName()
Return values
string —getPreviewImageUrl()
Returns the theme preview image URL.
public
getPreviewImageUrl() : string
If the image file doesn't exist returns the placeholder image URL.
Return values
string —Returns the image URL.
hasCustomData()
Returns true if this theme has form fields that supply customization data.
public
hasCustomData() : bool
Return values
bool —isActiveTheme()
Returns true if this theme is the chosen active theme.
public
isActiveTheme() : mixed
Return values
mixed —listPages()
Returns a list of pages in the theme.
public
listPages([bool $skipCache = false ]) : array<string|int, mixed>
This method is used internally in the routing process and in the back-end UI.
Parameters
- $skipCache : bool = false
-
Indicates if the pages should be reloaded from the disk bypassing the cache.
Return values
array<string|int, mixed> —Returns an array of \Cms\Classes\Page objects.
load()
Loads the theme.
public
static load(mixed $dirName) : self
Parameters
- $dirName : mixed
Return values
self —registerHalcyonDatasource()
Ensures this theme is registered as a Halcyon datasource.
public
registerHalcyonDatasource() : void
Return values
void —removeCustomData()
Remove data specific to this theme
public
removeCustomData() : bool
Return values
bool —resetCache()
Resets any memory or cache involved with the active or edit theme.
public
static resetCache() : void
Return values
void —setActiveTheme()
Sets the active theme.
public
static setActiveTheme(string $code) : mixed
The active theme code is stored in the database and overrides the configuration cms.activeTheme parameter.
Parameters
- $code : string
-
Specifies the active theme code.
Return values
mixed —setDirName()
Sets the theme directory name.
public
setDirName(mixed $dirName) : void
Parameters
- $dirName : mixed
Return values
void —writeConfig()
Writes to the theme.yaml file with the supplied array values.
public
writeConfig([array<string|int, mixed> $values = [] ][, array<string|int, mixed> $overwrite = false ]) : void
Parameters
- $values : array<string|int, mixed> = []
-
Data to write
- $overwrite : array<string|int, mixed> = false
-
If true, undefined values are removed.