diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index 322da06..33d880b 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -618,8 +618,10 @@ protected function postProcessExtension(array &$cache, ActiveTheme $theme) { // base hook is found. foreach ($grouped_functions[$first_prefix] as $candidate) { if (preg_match("/^{$prefix}_preprocess_(((?:[^_]++|_(?!_))+)__.*)/", $candidate, $matches)) { - $level = substr_count($matches[1], '__'); - $suggestion_level[$level][$candidate] = $matches[1]; + if (isset($cache[$matches[2]])) { + $level = substr_count($matches[1], '__'); + $suggestion_level[$level][$candidate] = $matches[1]; + } } } } @@ -648,14 +650,17 @@ protected function postProcessExtension(array &$cache, ActiveTheme $theme) { // @see https://www.drupal.org/node/2457295 if (isset($cache[$previous_hook])) { $cache[$hook] = $cache[$previous_hook]; - $cache[$hook]['base hook'] = $previous_hook; + // If a base hook isn't set, this is the actual base hook. + if (!isset($cache[$previous_hook]['base hook'])) { + $cache[$hook]['base hook'] = $previous_hook; + } $cache[$hook]['preprocess functions'][] = $preprocessor; } } } } } - // Inherit all base hook variable preprocess functions into pattern hooks. + // Inherit all base hook variable preprocess functions into suggestion hooks. // This ensures that derivative hooks have a complete set of variable // preprocess functions. foreach ($cache as $hook => $info) { @@ -663,8 +668,8 @@ protected function postProcessExtension(array &$cache, ActiveTheme $theme) { // from a pattern. This is typically set from // drupal_find_theme_functions() and drupal_find_theme_templates(). if (isset($info['base hook']) && isset($cache[$info['base hook']]['preprocess functions'])) { - $diff = array_diff($cache[$info['base hook']]['preprocess functions'], $info['preprocess functions']); - $cache[$hook]['preprocess functions'] = array_merge($diff, $info['preprocess functions']); + $diff = array_diff($info['preprocess functions'], $cache[$info['base hook']]['preprocess functions']); + $cache[$hook]['preprocess functions'] = array_merge($cache[$info['base hook']]['preprocess functions'], $diff); } // Optimize the registry. diff --git a/core/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php index 28a7767..687ae54 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManager.php +++ b/core/lib/Drupal/Core/Theme/ThemeManager.php @@ -290,7 +290,6 @@ protected function theme($hook, $variables = array()) { // Set a variable for the 'theme_hook_suggestion'. This is used to // maintain backwards compatibility with template engines. $theme_hook_suggestion = $hook; - $info['preprocess functions'] = $base_hook_info['preprocess functions'] + $info['preprocess functions']; } } if (isset($info['preprocess functions'])) {