diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index 0c1c25e..b09ef3b 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -605,45 +605,44 @@ protected function processExtension(array &$cache, $name, $type, $theme, $path) */ protected function completeSuggestion($hook, array &$cache) { $previous_hook = $hook; - $first_valid_hook = ''; + $incomplete_previous_hook = array(); // Continue looping if the candidate hook doesn't exist or if the candidate // hook has incomplete preprocess functions, and if the candidate hook is a // suggestion (has a double underscore). - while ((!isset($cache[$previous_hook]) || isset($cache[$previous_hook]['incomplete preprocess functions'])) && $pos = strrpos($previous_hook, '__')) { + while ((!isset($cache[$previous_hook]) || isset($cache[$previous_hook]['incomplete preprocess functions'])) + && $pos = strrpos($previous_hook, '__')) { // Find the first existing candidate hook that has incomplete preprocess // functions. - if (isset($cache[$previous_hook]) && !$first_valid_hook && isset($cache[$previous_hook]['incomplete preprocess functions'])) { - $first_valid_hook = $previous_hook; + if (isset($cache[$previous_hook]) && !$incomplete_previous_hook && isset($cache[$previous_hook]['incomplete preprocess functions'])) { + $incomplete_previous_hook = $cache[$previous_hook]; + unset($incomplete_previous_hook['incomplete preprocess functions']); } $previous_hook = substr($previous_hook, 0, $pos); - $this->mergePreprocessFunctions($hook, $previous_hook, $first_valid_hook, $cache); + $this->mergePreprocessFunctions($hook, $previous_hook, $incomplete_previous_hook, $cache); } // In addition to processing suggestions, include base hooks. if (isset($cache[$hook]['base hook']) && isset($cache[$cache[$hook]['base hook']])) { // Pass the current hook as the first valid hook if a base hook exists. - $this->mergePreprocessFunctions($hook, $cache[$hook]['base hook'], $hook, $cache); + $this->mergePreprocessFunctions($hook, $cache[$hook]['base hook'], $cache[$hook], $cache); } - - // Remove the incompleteness flag. - unset($cache[$hook]['incomplete preprocess functions']); } /** * Merges the source hook's preprocess functions into the destination hook's. * * @param string $destination_hook_name - * The name of the suggestion hook to complete. + * The name of the hook to merge preprocess functions to. * @param string $source_hook_name * The name of the hook to merge preprocess functions from. - * @param string $parent_hook_name - * The name of the parent hook if it exists. + * @param array $parent_hook + * The parent hook if it exists. Either an incomplete hook from suggestions + * or a base hook. * @param array $cache * The theme registry, as documented in * \Drupal\Core\Theme\Registry::processExtension(). */ - protected function mergePreprocessFunctions($destination_hook_name, $source_hook_name, $parent_hook_name, array &$cache) { - $parent_hook = isset($cache[$parent_hook_name]['incomplete preprocess functions']) ? $cache[$parent_hook_name] : []; + protected function mergePreprocessFunctions($destination_hook_name, $source_hook_name, $parent_hook, array &$cache) { // If base hook exists clone of it for the preprocess function // without a template. // @see https://www.drupal.org/node/2457295