diff --git a/core/includes/module.inc b/core/includes/module.inc index f7404cc..e412598 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -67,33 +67,6 @@ function system_list($type) { ); } } - // @todo Move into list_themes(). Read info for a particular requested - // theme from state instead. - foreach ($lists['theme'] as $key => $theme) { - if (!empty($theme->info['base theme'])) { - // Make a list of the theme's base themes. - require_once __DIR__ . '/theme.inc'; - $lists['theme'][$key]->base_themes = drupal_find_base_themes($lists['theme'], $key); - // Don't proceed if there was a problem with the root base theme. - if (!current($lists['theme'][$key]->base_themes)) { - continue; - } - // Determine the root base theme. - $base_key = key($lists['theme'][$key]->base_themes); - // Add to the list of sub-themes for each of the theme's base themes. - foreach (array_keys($lists['theme'][$key]->base_themes) as $base_theme) { - $lists['theme'][$base_theme]->sub_themes[$key] = $lists['theme'][$key]->info['name']; - } - // Add the base theme's theme engine info. - $lists['theme'][$key]->info['engine'] = $lists['theme'][$base_key]->info['engine']; - } - else { - // A plain theme is its own base theme. - $base_key = $key; - } - // Set the theme engine prefix. - $lists['theme'][$key]->prefix = ($lists['theme'][$key]->info['engine'] == 'theme') ? $base_key : $lists['theme'][$key]->info['engine']; - } \Drupal::cache('bootstrap')->set('system_list', $lists); } // To avoid a separate database lookup for the filepath, prime the diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 7ad60e5..25aec10 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -319,41 +319,8 @@ function drupal_theme_rebuild() { * @param $refresh * Whether to reload the list of themes from the database. Defaults to FALSE. * - * @return - * An associative array of the currently available themes. The keys are the - * themes' machine names and the values are objects having the following - * properties: - * - filename: The filepath and name of the .info.yml file. - * - name: The machine name of the theme. - * - status: 1 for enabled, 0 for disabled themes. - * - info: The contents of the .info.yml file. - * - stylesheets: A two dimensional array, using the first key for the - * media attribute (e.g. 'all'), the second for the name of the file - * (e.g. style.css). The value is a complete filepath (e.g. - * themes/bartik/style.css). Not set if no stylesheets are defined in the - * .info.yml file. - * - scripts: An associative array of JavaScripts, using the filename as key - * and the complete filepath as value. Not set if no scripts are defined in - * the .info.yml file. - * - prefix: The base theme engine prefix. - * - engine: The machine name of the theme engine. - * - base_theme: If this is a sub-theme, the machine name of the base theme - * defined in the .info.yml file. Otherwise, the element is not set. - * - base_themes: If this is a sub-theme, an associative array of the - * base-theme ancestors of this theme, starting with this theme's base - * theme, then the base theme's own base theme, etc. Each entry has an - * array key equal to the theme's machine name, and a value equal to the - * human-readable theme name; if a theme with matching machine name does - * not exist in the system, the value will instead be NULL (and since the - * system would not know whether that theme itself has a base theme, that - * will end the array of base themes). This is not set if the theme is not - * a sub-theme. - * - sub_themes: An associative array of themes on the system that are - * either direct sub-themes (that is, they declare this theme to be - * their base theme), direct sub-themes of sub-themes, etc. The keys are - * the themes' machine names, and the values are the themes' human-readable - * names. This element is not set if there are no themes on the system that - * declare this theme as their base theme. + * @return array + * An associative array of the currently available themes. * * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. * Use \Drupal::service('theme_handler')->listInfo(). @@ -373,30 +340,6 @@ function list_themes($refresh = FALSE) { } /** - * Finds all the base themes for the specified theme. - * - * Themes can inherit templates and function implementations from earlier - * themes. - * - * @param $themes - * An array of available themes. - * @param $key - * The name of the theme whose base we are looking for. - * - * @return - * Returns an array of all of the theme's ancestors; the first element's value - * will be NULL if an error occurred. - * - * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. - * Use \Drupal::service('theme_handler')->getBaseThemes(). - * - * @see \Drupal\Core\Extension\ThemeHandler::getBaseThemes(). - */ -function drupal_find_base_themes($themes, $key) { - return \Drupal::service('theme_handler')->getBaseThemes($themes, $key); -} - -/** * Generates themed output. * * All requests for themed output must go through this function (however, diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index fe828ee..419ad19 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -271,63 +271,64 @@ public function rebuildThemeData() { $sub_themes = array(); // Read info files for each theme. foreach ($themes as $key => $theme) { - $themes[$key]->filename = $theme->uri; - $themes[$key]->info = $this->infoParser->parse($theme->getPathname()) + $defaults; + $theme->filename = $theme->uri; + $theme->info = $this->infoParser->parse($theme->getPathname()) + $defaults; // Add the info file modification time, so it becomes available for // contributed modules to use for ordering theme lists. - $themes[$key]->info['mtime'] = $theme->getMTime(); + $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', $themes[$key]->info, $themes[$key], $type); + $this->moduleHandler->alter('system_info', $theme->info, $theme, $type); - if (!empty($themes[$key]->info['base theme'])) { - $sub_themes[] = $key; + // Defaults to 'twig' (see $defaults above). + $engine = $theme->info['engine']; + if (!isset($engines[$engine])) { + unset($themes[$key]); + continue; } + $theme->owner = $engines[$engine]->uri; + $theme->prefix = $engines[$engine]->name; - $engine = $themes[$key]->info['engine']; - if (isset($engines[$engine])) { - $themes[$key]->owner = $engines[$engine]->uri; - $themes[$key]->prefix = $engines[$engine]->name; - $themes[$key]->template = TRUE; + if (!empty($theme->info['base theme'])) { + $sub_themes[] = $key; } // Prefix stylesheets, scripts, and screenshot with theme path. $path = $theme->getPath(); $theme->info['stylesheets'] = $this->themeInfoPrefixPath($theme->info['stylesheets'], $path); $theme->info['scripts'] = $this->themeInfoPrefixPath($theme->info['scripts'], $path); - if (!empty($themes[$key]->info['screenshot'])) { - $themes[$key]->info['screenshot'] = $path . '/' . $themes[$key]->info['screenshot']; + if (!empty($theme->info['screenshot'])) { + $theme->info['screenshot'] = $path . '/' . $theme->info['screenshot']; } } - // Now that we've established all our master themes, go back and fill in - // data for sub-themes. + // After establishing the full list of available themes, fill in data for + // sub-themes. foreach ($sub_themes as $key) { - $themes[$key]->base_themes = $this->getBaseThemes($themes, $key); - // Don't proceed if there was a problem with the root base theme. - if (!current($themes[$key]->base_themes)) { + $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; } - $base_key = key($themes[$key]->base_themes); - foreach (array_keys($themes[$key]->base_themes) as $base_theme) { - $themes[$base_theme]->sub_themes[$key] = $themes[$key]->info['name']; - } - // Copy the 'owner' and 'engine' over if the top level theme uses a theme - // engine. - if (isset($themes[$base_key]->owner)) { - if (isset($themes[$base_key]->info['engine'])) { - $themes[$key]->info['engine'] = $themes[$base_key]->info['engine']; - $themes[$key]->owner = $themes[$base_key]->owner; - $themes[$key]->prefix = $themes[$base_key]->prefix; - } - else { - $themes[$key]->prefix = $key; - } + // 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. + $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;