class ThemeInitialization implements ThemeInitializationInterface (View source)

Provides the theme initialization logic.

Properties

protected ThemeHandlerInterface $themeHandler

The theme handler.

protected CacheBackendInterface $cache

The cache backend to use for the active theme.

protected string $root

The app root.

protected array $extensions

The extensions that might be attaching assets.

protected ModuleHandlerInterface $moduleHandler

The module handler.

Methods

__construct(string $root, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler)

Constructs a new ThemeInitialization object.

initTheme(string $theme_name)

Initializes a given theme.

getActiveThemeByName(string $theme_name)

Builds an active theme object.

loadActiveTheme(ActiveTheme $active_theme)

Loads a theme, so it is ready to be used.

getActiveTheme(Extension $theme, array $base_themes = [])

Builds up the active theme object from extensions.

array
getExtensions()

Gets all extensions.

string
resolveStyleSheetPlaceholders(string $css_file)

Gets CSS file where tokens have been resolved.

string[]
prepareStylesheetsRemove(Extension $theme, Extension[] $base_themes)

Prepares stylesheets-remove specified in the *.info.yml file.

Details

__construct(string $root, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler)

Constructs a new ThemeInitialization object.

Parameters

string $root

The app root.

ThemeHandlerInterface $theme_handler

The theme handler.

CacheBackendInterface $cache

The cache backend.

ModuleHandlerInterface $module_handler

The module handler to use to load modules.

ActiveTheme initTheme(string $theme_name)

Initializes a given theme.

This loads the active theme, for example include its engine file.

Parameters

string $theme_name

The machine name of the theme.

Return Value

ActiveTheme

An active theme object instance for the given theme.

ActiveTheme getActiveThemeByName(string $theme_name)

Builds an active theme object.

Parameters

string $theme_name

The machine name of the theme.

Return Value

ActiveTheme

An active theme object instance for the given theme.

Exceptions

MissingThemeDependencyException

loadActiveTheme(ActiveTheme $active_theme)

Loads a theme, so it is ready to be used.

Loading a theme includes loading and initializing the engine, each base theme and its engines.

Parameters

ActiveTheme $active_theme

The theme to load.

ActiveTheme getActiveTheme(Extension $theme, array $base_themes = [])

Builds up the active theme object from extensions.

Parameters

Extension $theme

The theme extension object.

array $base_themes

An array of extension objects of base theme and its bases. It is ordered by 'next parent first', meaning the top level of the chain will be first.

Return Value

ActiveTheme

The active theme instance for the passed in $theme.

protected array getExtensions()

Gets all extensions.

Return Value

array

protected string resolveStyleSheetPlaceholders(string $css_file)

Gets CSS file where tokens have been resolved.

Remove in Drupal 9.0.x.

Parameters

string $css_file

CSS file which may contain tokens.

Return Value

string

CSS file where placeholders are replaced.

protected string[] prepareStylesheetsRemove(Extension $theme, Extension[] $base_themes)

internal  
 

Prepares stylesheets-remove specified in the *.info.yml file.

This method is used as a BC layer to access the contents of the deprecated stylesheets-remove key in theme info.yml files. It will be removed once it is no longer needed in Drupal 10.

Remove in Drupal 10.0.x.

Parameters

Extension $theme

The theme extension object.

Extension[] $base_themes

An array of base themes.

Return Value

string[]

The list of stylesheets-remove specified in the *.info.yml file.