function ThemeExtensionList::doGetBaseThemes

Same name in other branches
  1. 9 core/lib/Drupal/Core/Extension/ThemeExtensionList.php \Drupal\Core\Extension\ThemeExtensionList::doGetBaseThemes()
  2. 8.9.x core/lib/Drupal/Core/Extension/ThemeExtensionList.php \Drupal\Core\Extension\ThemeExtensionList::doGetBaseThemes()
  3. 10 core/lib/Drupal/Core/Extension/ThemeExtensionList.php \Drupal\Core\Extension\ThemeExtensionList::doGetBaseThemes()

Finds the base themes for the specific theme.

Parameters

array $themes: An array of available themes.

string $theme: The name of the theme whose base we are looking for.

array $used_themes: (optional) A recursion parameter preventing endless loops. Defaults to an empty array.

Return value

array An array of base themes.

2 calls to ThemeExtensionList::doGetBaseThemes()
ThemeExtensionList::fillInSubThemeData in core/lib/Drupal/Core/Extension/ThemeExtensionList.php
Fills in data for themes that are also sub-themes.
ThemeExtensionList::getBaseThemes in core/lib/Drupal/Core/Extension/ThemeExtensionList.php
Finds all the base themes for the specified theme.

File

core/lib/Drupal/Core/Extension/ThemeExtensionList.php, line 238

Class

ThemeExtensionList
Provides a list of available themes.

Namespace

Drupal\Core\Extension

Code

protected function doGetBaseThemes(array $themes, $theme, array $used_themes = []) {
    if (!isset($themes[$theme]->info['base theme'])) {
        return [];
    }
    $base_key = $themes[$theme]->info['base theme'];
    // Does the base theme exist?
    if (!isset($themes[$base_key])) {
        return [
            $base_key => NULL,
        ];
    }
    $current_base_theme = [
        $base_key => $themes[$base_key]->info['name'],
    ];
    // Is the base theme itself a child of another theme?
    if (isset($themes[$base_key]->info['base theme'])) {
        // Do we already know the base themes of this theme?
        if (isset($themes[$base_key]->base_themes)) {
            return $themes[$base_key]->base_themes + $current_base_theme;
        }
        // Prevent loops.
        if (!empty($used_themes[$base_key])) {
            return [
                $base_key => NULL,
            ];
        }
        $used_themes[$base_key] = TRUE;
        return $this->doGetBaseThemes($themes, $base_key, $used_themes) + $current_base_theme;
    }
    // If we get here, then this is our parent theme.
    return $current_base_theme;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.