Drupal\helper\Theme
Helper service for working with themes.
Methods
| Name | Description |
|---|---|
| __construct | Constructs a Theme helper. |
| isActive | Checks if a theme is the active theme or one of the active base themes. |
| isBaseTheme | Checks if a theme is a base theme of a sub-theme. |
| isDefault | Checks if a theme is the default theme or one of the default base themes. |
| setDefault | Sets the default theme. |
| switch | Switches to the specified theme. |
| switchBack | Switches back to the previous theme. |
Theme::__construct
Description
public __construct (\Drupal\Core\Extension\ThemeHandlerInterface $themeHandler, \Drupal\Core\Theme\ThemeManagerInterface $themeManager, \Drupal\Core\Extension\ThemeInstallerInterface $themeInstaller, \Drupal\Core\Config\ConfigFactoryInterface $configFactory, \Drupal\Core\Theme\ThemeInitializationInterface $themeInitialization, \Drupal\Core\Extension\ThemeExtensionList $themeExtensionList)
Constructs a Theme helper.
Parameters
(\Drupal\Core\Extension\ThemeHandlerInterface) $themeHandler:
Theme handler.(\Drupal\Core\Theme\ThemeManagerInterface) $themeManager:
Theme manager.(\Drupal\Core\Extension\ThemeInstallerInterface) $themeInstaller:
Theme installer.(\Drupal\Core\Config\ConfigFactoryInterface) $configFactory:
Configuration factory.(\Drupal\Core\Theme\ThemeInitializationInterface) $themeInitialization:
Theme initialization.(\Drupal\Core\Extension\ThemeExtensionList) $themeExtensionList:
Theme extension list.
Return Values
void
Theme::isActive
Description
public isActive (string $theme_name, bool $check_base_themes)
Checks if a theme is the active theme or one of the active base themes.
Parameters
(string) $theme_name:
Theme name.(bool) $check_base_themes:
TRUE to check if the theme is in the base themes of the active theme.
Return Values
bool
TRUE if the theme is active, or FALSE otherwise.
Theme::isBaseTheme
Description
public isBaseTheme (string $base_theme, string|null $sub_theme_name)
Checks if a theme is a base theme of a sub-theme.
Parameters
(string) $base_theme:
The theme that is potentially a base theme.(string|null) $sub_theme_name:
The sub theme name to check for the base theme.
Return Values
bool
TRUE if the theme is a base theme or FALSE otherwise.
Theme::isDefault
Description
public isDefault (string $theme_name, bool $check_base_themes)
Checks if a theme is the default theme or one of the default base themes.
Parameters
(string) $theme_name:
Theme name.(bool) $check_base_themes:
TRUE to check if the theme is in the base themes of the default theme.
Return Values
bool
TRUE if the theme is default, or FALSE otherwise.
Theme::setDefault
Description
public setDefault (string $theme_name)
Sets the default theme.
Parameters
(string) $theme_name:
Theme name.
Return Values
bool
TRUE if the default theme was updated, or FALSE if the requested theme
was already the default.
Theme::switch
Description
public switch (string $theme_name)
Switches to the specified theme.
Parameters
(string) $theme_name:
Theme name.
Return Values
void
Throws Exceptions
\InvalidArgumentException
If the theme does not exist or is not installed.
Theme::switchBack
Description
public switchBack (void)
Switches back to the previous theme.
Parameters
This function has no parameters.
Return Values
void
Throws Exceptions
\RuntimeException
If there are no more themes to revert to.