diff --git a/src/Plugin/Alter/ThemeRegistry.php b/src/Plugin/Alter/ThemeRegistry.php index 86ae77015d9c83d7acb4db8d7346d869bded1b92..7ff3ac7c51554bf4c5fe8cba3971e287e00acd12 100644 --- a/src/Plugin/Alter/ThemeRegistry.php +++ b/src/Plugin/Alter/ThemeRegistry.php @@ -87,12 +87,23 @@ class ThemeRegistry extends Registry implements AlterInterface { $hook = str_replace('-', '_', str_replace('.html.twig', '', $file->filename)); $path = dirname($file->uri); $incomplete = !isset($cache[$hook]) || strrpos($hook, '__'); + + // Create a new theme hook. This primarily happens when theme hook + // suggestion templates are created. To prevent the new hook from + // inheriting parent hook's "template", it must be manually set here. + // @see https://www.drupal.org/node/2871551 if (!isset($cache[$hook])) { - $cache[$hook] = []; + $cache[$hook] = [ + 'template' => str_replace('.html.twig', '', $file->filename), + ]; } + + // Always ensure that "path", "type" and "theme path" are properly set. $cache[$hook]['path'] = $path; $cache[$hook]['type'] = $current_theme ? 'theme' : 'base_theme'; $cache[$hook]['theme path'] = $theme_path; + + // Flag incomplete. if ($incomplete) { $cache[$hook]['incomplete preprocess functions'] = TRUE; }