function ThemeExtensionList::doList

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

Overrides ExtensionList::doList

File

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

Class

ThemeExtensionList
Provides a list of available themes.

Namespace

Drupal\Core\Extension

Code

protected function doList() {
    // Find themes.
    $themes = parent::doList();
    $engines = $this->engineList
        ->getList();
    // Always get the freshest list of themes (rather than the already cached
    // list in $this->installedThemes) when building the theme listing because a
    // theme could have just been installed or uninstalled.
    $this->installedThemes = $this->configFactory
        ->get('core.extension')
        ->get('theme') ?: [];
    $sub_themes = [];
    // Read info files for each theme.
    foreach ($themes as $name => $theme) {
        // Defaults to 'twig' (see self::defaults above).
        $engine = $theme->info['engine'];
        if (isset($engines[$engine])) {
            $theme->owner = $engines[$engine]->getExtensionPathname();
            $theme->prefix = $engines[$engine]->getName();
        }
        // Add this theme as a sub-theme if it has a base theme.
        if (!empty($theme->info['base theme'])) {
            $sub_themes[] = $name;
        }
        // Add status.
        $theme->status = (int) isset($this->installedThemes[$name]);
    }
    // Build dependencies.
    $themes = $this->moduleHandler
        ->buildModuleDependencies($themes);
    // After establishing the full list of available themes, fill in data for
    // sub-themes.
    $this->fillInSubThemeData($themes, $sub_themes);
    foreach ($themes as $theme) {
        // After $theme is processed by buildModuleDependencies(), there can be a
        // `$theme->requires` array containing both module and base theme
        // dependencies. The module dependencies are copied to their own property
        // so they are available to operations specific to module dependencies.
        if (isset($theme->requires)) {
            $theme->module_dependencies = array_diff_key($theme->requires, $themes);
        }
        else {
            // Even if no requirements are specified, the theme installation process
            // expects the presence of the `requires` and `module_dependencies`
            // properties, so they should be initialized here as empty arrays.
            $theme->requires = [];
            $theme->module_dependencies = [];
        }
    }
    return $themes;
}

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