Skip to content

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.

Theme::__construct

Description

public __construct (\Drupal\Core\Extension\ThemeHandlerInterface $theme_handler, \Drupal\Core\Theme\ThemeManagerInterface $theme_manager, \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer, \Drupal\Core\Config\ConfigFactoryInterface $config_factory)

Constructs a Theme helper.

Parameters

  • (\Drupal\Core\Extension\ThemeHandlerInterface) $theme_handler : Theme handler.
  • (\Drupal\Core\Theme\ThemeManagerInterface) $theme_manager : Theme manager.
  • (\Drupal\Core\Extension\ThemeInstallerInterface) $theme_installer : Theme installer.
  • (\Drupal\Core\Config\ConfigFactoryInterface) $config_factory : Configuration factory.

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 $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) $theme_name : The sub theme name to check for base themes.

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.