public function ThemeInitialization::getActiveThemeByName in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Theme/ThemeInitialization.php \Drupal\Core\Theme\ThemeInitialization::getActiveThemeByName()
- 9 core/lib/Drupal/Core/Theme/ThemeInitialization.php \Drupal\Core\Theme\ThemeInitialization::getActiveThemeByName()
File
- core/lib/Drupal/Core/Theme/ThemeInitialization.php, line 82
Class
- ThemeInitialization
- Provides the theme initialization logic.
Namespace
Drupal\Core\Theme
Code
public function getActiveThemeByName($theme_name) {
if ($cached = $this->cache
->get('theme.active_theme.' . $theme_name)) {
return $cached->data;
}
$themes = $this->themeHandler
->listInfo();
if (empty($themes) || !$theme_name || !isset($themes[$theme_name])) {
$theme_name = 'core';
$active_theme = $this
->getActiveTheme(new Extension($this->root, 'theme', 'core/core.info.yml'));
return $active_theme;
}
$base_themes = [];
$ancestor = $theme_name;
while ($ancestor && isset($themes[$ancestor]->base_theme)) {
$ancestor = $themes[$ancestor]->base_theme;
if (!$this->themeHandler
->themeExists($ancestor)) {
if ($ancestor == 'stable') {
continue;
}
throw new MissingThemeDependencyException(sprintf('Base theme %s has not been installed.', $ancestor), $ancestor);
}
$base_themes[] = $themes[$ancestor];
}
$active_theme = $this
->getActiveTheme($themes[$theme_name], $base_themes);
$this->cache
->set('theme.active_theme.' . $theme_name, $active_theme);
return $active_theme;
}