You are here

protected function ThemeExtensionList::doList in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Extension/ThemeExtensionList.php \Drupal\Core\Extension\ThemeExtensionList::doList()
  2. 9 core/lib/Drupal/Core/Extension/ThemeExtensionList.php \Drupal\Core\Extension\ThemeExtensionList::doList()

Builds the list of extensions.

Return value

\Drupal\Core\Extension\Extension[] Processed extension objects, keyed by machine name.

Throws

\Drupal\Core\Extension\InfoParserException If one of the .info.yml files is incomplete, or causes a parsing error.

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;
}