class ThemeManager implements ThemeManagerInterface (View source)

Provides the default implementation of a theme manager.

Properties

protected ThemeNegotiatorInterface $themeNegotiator

The theme negotiator.

protected Registry $themeRegistry

The theme registry used to render an output.

protected ActiveTheme $activeTheme

Contains the current active theme.

protected ThemeInitializationInterface $themeInitialization

The theme initialization.

protected ModuleHandlerInterface $moduleHandler

The module handler.

protected string $root

The app root.

Methods

__construct(string $root, ThemeNegotiatorInterface $theme_negotiator, ThemeInitializationInterface $theme_initialization, ModuleHandlerInterface $module_handler)

Constructs a new ThemeManager object.

$this
setThemeRegistry(Registry $theme_registry)

Sets the theme registry.

getActiveTheme(RouteMatchInterface $route_match = NULL)

Returns the active theme object.

bool
hasActiveTheme()

Determines whether there is an active theme.

$this
resetActiveTheme()

Resets the current active theme.

$this
setActiveTheme(ActiveTheme $active_theme)

Sets the current active theme manually.

render(string $hook, array $variables)

Generates themed output.

initTheme(RouteMatchInterface $route_match = NULL)

Initializes the active theme for a given route match.

alterForTheme(ActiveTheme $theme, string|array $type, mixed $data, mixed $context1 = NULL, mixed $context2 = NULL)

Provides an alter hook for a specific theme.

alter(string|array $type, mixed $data, mixed $context1 = NULL, mixed $context2 = NULL)

Passes alterable variables to specific $theme_TYPE_alter() implementations.

Details

__construct(string $root, ThemeNegotiatorInterface $theme_negotiator, ThemeInitializationInterface $theme_initialization, ModuleHandlerInterface $module_handler)

Constructs a new ThemeManager object.

Parameters

string $root

The app root.

ThemeNegotiatorInterface $theme_negotiator

The theme negotiator.

ThemeInitializationInterface $theme_initialization

The theme initialization.

ModuleHandlerInterface $module_handler

The module handler.

$this setThemeRegistry(Registry $theme_registry)

Sets the theme registry.

Parameters

Registry $theme_registry

The theme registry.

Return Value

$this

ActiveTheme getActiveTheme(RouteMatchInterface $route_match = NULL)

Returns the active theme object.

Parameters

RouteMatchInterface $route_match

The route match.

Return Value

ActiveTheme

bool hasActiveTheme()

Determines whether there is an active theme.

Return Value

bool

$this resetActiveTheme()

Resets the current active theme.

Note: This method should not be used in common cases, just in special cases like tests.

Return Value

$this

$this setActiveTheme(ActiveTheme $active_theme)

Sets the current active theme manually.

Note: This method should not be used in common cases, just in special cases like tests.

Parameters

ActiveTheme $active_theme

The new active theme.

Return Value

$this

string|MarkupInterface render(string $hook, array $variables)

Generates themed output.

See the @link themeable Default theme implementations topic @endlink for details.

Parameters

string $hook

The name of the theme hook to call.

array $variables

An associative array of theme variables.

Return Value

string|MarkupInterface

The rendered output, or a Markup object.

protected initTheme(RouteMatchInterface $route_match = NULL)

Initializes the active theme for a given route match.

Parameters

RouteMatchInterface $route_match

The current route match.

alterForTheme(ActiveTheme $theme, string|array $type, mixed $data, mixed $context1 = NULL, mixed $context2 = NULL)

Provides an alter hook for a specific theme.

Similar to ::alter, it also invokes the alter hooks for the base themes.

Should we cache some of these information?

Parameters

ActiveTheme $theme

A manually specified theme.

string|array $type

A string describing the type of the alterable $data.

mixed $data

The variable that will be passed to $theme_TYPE_alter() implementations

mixed $context1

(optional) An additional variable that is passed by reference.

mixed $context2

(optional) An additional variable that is passed by reference.

alter(string|array $type, mixed $data, mixed $context1 = NULL, mixed $context2 = NULL)

Passes alterable variables to specific $theme_TYPE_alter() implementations.

Executes an alter hook on the current theme. It also invokes alter hooks for all base themes.

$theme specifies the theme name of the active theme and all its base themes.

This dispatch function hands off the passed-in variables to type-specific $theme_TYPE_alter() implementations in the active theme. It ensures a consistent interface for all altering operations.

A maximum of 2 alterable arguments is supported. In case more arguments need to be passed and alterable, modules provide additional variables assigned by reference in the last $context argument:

Parameters

string|array $type

A string describing the type of the alterable $data. 'form', 'links', 'node_content', and so on are several examples. Alternatively can be an array, in which case $theme_TYPE_alter() is invoked for each value in the array. When Form API is using $this->alter() to execute both $theme_form_alter() and $theme_form_FORM_IDalter() implementations, it passes array('form', 'form' . $form_id) for $type.

mixed $data

The variable that will be passed to $theme_TYPE_alter() implementations to be altered. The type of this variable depends on the value of the $type argument. For example, when altering a 'form', $data will be a structured array. When altering a 'profile', $data will be an object.

mixed $context1

(optional) An additional variable that is passed by reference.

mixed $context2

(optional) An additional variable that is passed by reference. If more context needs to be provided to implementations, then this should be an associative array as described above.