function ThemeInitialization::getActiveTheme
Same name in other branches
- 9 core/lib/Drupal/Core/Theme/ThemeInitialization.php \Drupal\Core\Theme\ThemeInitialization::getActiveTheme()
- 10 core/lib/Drupal/Core/Theme/ThemeInitialization.php \Drupal\Core\Theme\ThemeInitialization::getActiveTheme()
- 11.x core/lib/Drupal/Core/Theme/ThemeInitialization.php \Drupal\Core\Theme\ThemeInitialization::getActiveTheme()
Overrides ThemeInitializationInterface::getActiveTheme
1 call to ThemeInitialization::getActiveTheme()
- ThemeInitialization::getActiveThemeByName in core/
lib/ Drupal/ Core/ Theme/ ThemeInitialization.php - Builds an active theme object.
File
-
core/
lib/ Drupal/ Core/ Theme/ ThemeInitialization.php, line 170
Class
- ThemeInitialization
- Provides the theme initialization logic.
Namespace
Drupal\Core\ThemeCode
public function getActiveTheme(Extension $theme, array $base_themes = []) {
$theme_path = $theme->getPath();
$values['path'] = $theme_path;
$values['name'] = $theme->getName();
// Use the logo declared in this themes info file, otherwise use logo.svg
// from the themes root.
if (!empty($theme->info['logo'])) {
$values['logo'] = $theme->getPath() . '/' . $theme->info['logo'];
}
else {
$values['logo'] = $theme->getPath() . '/logo.svg';
}
// @todo Remove in Drupal 10.0.x.
$values['stylesheets_remove'] = $this->prepareStylesheetsRemove($theme, $base_themes);
// Prepare libraries overrides from this theme and ancestor themes. This
// allows child themes to easily remove CSS files from base themes and
// modules.
$values['libraries_override'] = [];
// Get libraries overrides declared by base themes.
foreach ($base_themes as $base) {
if (!empty($base->info['libraries-override'])) {
foreach ($base->info['libraries-override'] as $library => $override) {
$values['libraries_override'][$base->getPath()][$library] = $override;
}
}
}
// Add libraries overrides declared by this theme.
if (!empty($theme->info['libraries-override'])) {
foreach ($theme->info['libraries-override'] as $library => $override) {
$values['libraries_override'][$theme->getPath()][$library] = $override;
}
}
// Get libraries extensions declared by base themes.
foreach ($base_themes as $base) {
if (!empty($base->info['libraries-extend'])) {
foreach ($base->info['libraries-extend'] as $library => $extend) {
if (isset($values['libraries_extend'][$library])) {
// Merge if libraries-extend has already been defined for this
// library.
$values['libraries_extend'][$library] = array_merge($values['libraries_extend'][$library], $extend);
}
else {
$values['libraries_extend'][$library] = $extend;
}
}
}
}
// Add libraries extensions declared by this theme.
if (!empty($theme->info['libraries-extend'])) {
foreach ($theme->info['libraries-extend'] as $library => $extend) {
if (isset($values['libraries_extend'][$library])) {
// Merge if libraries-extend has already been defined for this
// library.
$values['libraries_extend'][$library] = array_merge($values['libraries_extend'][$library], $extend);
}
else {
$values['libraries_extend'][$library] = $extend;
}
}
}
// Do basically the same as the above for libraries
$values['libraries'] = [];
// Grab libraries from base theme
foreach ($base_themes as $base) {
if (!empty($base->libraries)) {
foreach ($base->libraries as $library) {
$values['libraries'][] = $library;
}
}
}
// Add libraries used by this theme.
if (!empty($theme->libraries)) {
foreach ($theme->libraries as $library) {
$values['libraries'][] = $library;
}
}
$values['engine'] = isset($theme->engine) ? $theme->engine : NULL;
$values['owner'] = isset($theme->owner) ? $theme->owner : NULL;
$values['extension'] = $theme;
$base_active_themes = [];
foreach ($base_themes as $base_theme) {
$base_active_themes[$base_theme->getName()] = $base_theme;
}
$values['base_theme_extensions'] = $base_active_themes;
if (!empty($theme->info['regions'])) {
$values['regions'] = $theme->info['regions'];
}
return new ActiveTheme($values);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.