From ff2d0bb65398b1a38b3d2ba22b6f8789c3831643 Mon Sep 17 00:00:00 2001
From: jacintocapote <jacintocapote@348228.no-reply.drupal.org>
Date: Thu, 20 Apr 2017 15:14:06 -0500
Subject: [PATCH] Issue #2871551 by fastangel, markcarver: Problem to find
 template file

---
 src/Plugin/Alter/ThemeRegistry.php | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/Plugin/Alter/ThemeRegistry.php b/src/Plugin/Alter/ThemeRegistry.php
index 86ae770..7ff3ac7 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;
         }
-- 
2.12.2

