Cms\Classes\Theme

Source: ~/modules/cms/classes/Theme.php

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.

Protected properties

protected string $dirName

Specifies the theme directory name.

protected mixed $configCache

Keeps the cached configuration file values.

protected static mixed $activeThemeCache

Active theme cache in memory

protected static mixed $editThemeCache

Edit theme cache in memory

Public methods

public void __get(string $name)

Implements the getter functionality.

Parameters
  • string $name

public void __isset(string $key)

Determine if an attribute exists on the object.

Parameters
  • string $key

public static array all()

Returns a list of all themes.

public static boolean databaseLayerEnabled()

Checks to see if the database layer has been enabled

public static bool exists(string $dirName)

Determines if a theme with given directory name exists

Parameters
  • string $dirName - The theme directory

public static Cms\Classes\Theme getActiveTheme()

Returns the active theme object.

public static string getActiveThemeCode()

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.theme.getActiveTheme event listener.

public array getConfig()

Reads the theme.yaml file and returns the theme configuration values.

public array getConfigArray(string $name)

Returns an array value from the theme configuration file by its name. If the value is a string, it is treated as a YAML file and loaded.

Parameters
  • string $name - Specifies the configuration parameter name.

public mixed getConfigValue(string $name, mixed $default=NULL)

Returns a value from the theme configuration file by its name.

Parameters
  • string $name - Specifies the configuration parameter name.
  • mixed $default - Specifies the default value to return in case if the parameter doesn't exist in the configuration file.

public Cms\Models\ThemeData getCustomData()

Returns data specific to this theme

public DatasourceInterface getDatasource()

Get the theme's datasource

public string getDirName()

Returns the theme directory name.

public static Cms\Classes\Theme getEditTheme()

Returns the edit theme.

public static string getEditThemeCode()

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.theme.getEditTheme event listeners. If the edit theme is not defined in the configuration file, the active theme is returned.

public array 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 string getId()

Helper for {{ theme.id }} twig vars Returns a unique string for this theme.

public string getPath(string $dirName=NULL)

Returns the absolute theme path.

Parameters
  • string $dirName - Optional theme directory. Defaults to $this->getDirName()

public string getPreviewImageUrl()

Returns the theme preview image URL. If the image file doesn't exist returns the placeholder image URL.

public bool hasCustomData()

Returns true if this theme has form fields that supply customization data.

public void isActiveTheme()

Returns true if this theme is the chosen active theme.

public array listPages(boolean $skipCache=false)

Returns a list of pages in the theme. This method is used internally in the routing process and in the back-end UI.

Parameters
  • boolean $skipCache - Indicates if the pages should be reloaded from the disk bypassing the cache.

public static self load($dirName)

Loads the theme.

Parameters
  • $dirName

public void registerHalyconDatasource()

Ensures this theme is registered as a Halcyon datasource.

public bool removeCustomData()

Remove data specific to this theme

public static void resetCache()

Resets any memory or cache involved with the active or edit theme.

public static void setActiveTheme(string $code)

Sets the active theme. The active theme code is stored in the database and overrides the configuration cms.activeTheme parameter.

Parameters
  • string $code - Specifies the active theme code.

public void setDirName($dirName)

Sets the theme directory name.

Parameters
  • $dirName

public void writeConfig(array $values=array(), array $overwrite=false)

Writes to the theme.yaml file with the supplied array values.

Parameters
  • array $values - Data to write
  • array $overwrite - If true, undefined values are removed.