public ThemeHandler::rebuildThemeData()
Scans and collects theme extension data and their engines.
Return value
\Drupal\Core\Extension\Extension[] An associative array of theme extensions.
Overrides ThemeHandlerInterface::rebuildThemeData
File
- core/lib/Drupal/Core/Extension/ThemeHandler.php, line 245
Class
- ThemeHandler
- Default theme handler using the config system to store installation statuses.
Namespace
Drupal\Core\Extension
Code
public function rebuildThemeData() { $listing = $this->getExtensionDiscovery(); $themes = $listing->scan('theme'); $engines = $listing->scan('theme_engine'); $extension_config = $this->configFactory->get('core.extension'); $installed = $extension_config->get('theme') ? : array(); // Set defaults for theme info. $defaults = array( 'engine' => 'twig', 'base theme' => 'stable', 'regions' => array( 'sidebar_first' => 'Left sidebar', 'sidebar_second' => 'Right sidebar', 'content' => 'Content', 'header' => 'Header', 'primary_menu' => 'Primary menu', 'secondary_menu' => 'Secondary menu', 'footer' => 'Footer', 'highlighted' => 'Highlighted', 'help' => 'Help', 'page_top' => 'Page top', 'page_bottom' => 'Page bottom', 'breadcrumb' => 'Breadcrumb', ), 'description' => '', 'features' => $this->defaultFeatures, 'screenshot' => 'screenshot.png', 'php' => DRUPAL_MINIMUM_PHP, 'libraries' => array(), ); $sub_themes = array(); $files_theme = array(); $files_theme_engine = array(); // Read info files for each theme. foreach ($themes as $key => $theme) { // @todo Remove all code that relies on the $status property. $theme->status = (int) isset($installed[$key]); $theme->info = $this->infoParser->parse($theme->getPathname()) + $defaults; // Remove the default Stable base theme when 'base theme: false' is set in // a theme .info.yml file. if ($theme->info['base theme'] === FALSE) { unset($theme->info['base theme']); } // Add the info file modification time, so it becomes available for // contributed modules to use for ordering theme lists. $theme->info['mtime'] = $theme->getMTime(); // Invoke hook_system_info_alter() to give installed modules a chance to // modify the data in the .info.yml files if necessary. // @todo Remove $type argument, obsolete with $theme->getType(). $type = 'theme'; $this->moduleHandler->alter('system_info', $theme->info, $theme, $type); if (!empty($theme->info['base theme'])) { $sub_themes[] = $key; // Add the base theme as a proper dependency. $themes[$key]->info['dependencies'][] = $themes[$key]->info['base theme']; } // Defaults to 'twig' (see $defaults above). $engine = $theme->info['engine']; if (isset($engines[$engine])) { $theme->owner = $engines[$engine]->getExtensionPathname(); $theme->prefix = $engines[$engine]->getName(); $files_theme_engine[$engine] = $engines[$engine]->getPathname(); } // Prefix screenshot with theme path. if (!empty($theme->info['screenshot'])) { $theme->info['screenshot'] = $theme->getPath() . '/' . $theme->info['screenshot']; } $files_theme[$key] = $theme->getPathname(); } // Build dependencies. // @todo Move into a generic ExtensionHandler base class. // @see https://www.drupal.org/node/2208429 $themes = $this->moduleHandler->buildModuleDependencies($themes); // Store filenames to allow system_list() and drupal_get_filename() to // retrieve them for themes and theme engines without having to scan the // filesystem. $this->state->set('system.theme.files', $files_theme); $this->state->set('system.theme_engine.files', $files_theme_engine); // After establishing the full list of available themes, fill in data for // sub-themes. foreach ($sub_themes as $key) { $sub_theme = $themes[$key]; // The $base_themes property is optional; only set for sub themes. // @see ThemeHandlerInterface::listInfo() $sub_theme->base_themes = $this->getBaseThemes($themes, $key); // empty() cannot be used here, since ThemeHandler::doGetBaseThemes() adds // the key of a base theme with a value of NULL in case it is not found, // in order to prevent needless iterations. if (!current($sub_theme->base_themes)) { continue; } // Determine the root base theme. $root_key = key($sub_theme->base_themes); // Build the list of sub-themes for each of the theme's base themes. foreach (array_keys($sub_theme->base_themes) as $base_theme) { $themes[$base_theme]->sub_themes[$key] = $sub_theme->info['name']; } // Add the theme engine info from the root base theme. if (isset($themes[$root_key]->owner)) { $sub_theme->info['engine'] = $themes[$root_key]->info['engine']; $sub_theme->owner = $themes[$root_key]->owner; $sub_theme->prefix = $themes[$root_key]->prefix; } } return $themes; }
Please login to continue.