Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294542

Logical error when register theme hook by scanning templates

$
0
0

Drupal allows sub theme extensions to be placed in the base theme extension directory. The sub theme directory needs to be excluded when the base theme scan template registers theme hooks. But the current implementation, the logic is incorrect.

The bug comes from:
(core/includes/theme.inc) drupal_find_theme_templates($cache, $extension, $path) line199-213:

  $theme_paths = [];
  foreach (\Drupal::service('theme_handler')->listInfo() as $theme_info) {
    if (!empty($theme_info->base_theme)) {
      $theme_paths[$theme_info->base_theme][$theme_info->getName()] = $theme_info->getPath();
    }
  }
  foreach ($theme_paths as $basetheme => $subthemes) {
    foreach ($subthemes as $subtheme => $subtheme_path) {
      if (isset($theme_paths[$subtheme])) {
        $theme_paths[$basetheme] = array_merge($theme_paths[$basetheme], $theme_paths[$subtheme]);
      }
    }
  }
  $theme = \Drupal::theme()->getActiveTheme()->getName();
  $subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : [];

Can be replaced with the following code to fix:

    $theme_paths = [];
    $theme_list = \Drupal::service('theme_handler')->listInfo();
    foreach ($theme_list as $theme_info) {
        $current_theme = $theme_info;
        while (!empty($current_theme->base_theme)) {
            $theme_paths[$current_theme->base_theme][$theme_info->name] = $theme_info->path;
            $current_theme = $theme_list[$current_theme->base_theme];
        }
    }
    $theme = $theme ; 
//In the inheritance chain, $theme is the theme currently being processed, and it should be passed in through the parameters.
    $subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : [];

Viewing all articles
Browse latest Browse all 294542


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>