diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 1d24dd5..72cbbaa 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -919,6 +919,8 @@ function theme($hook, $variables = array()) { $hooks = theme_get_registry(FALSE); + $theme_hooks = $hook; + // If an array of hook candidates were passed, use the first one that has an // implementation. if (is_array($hook)) { @@ -1018,9 +1020,11 @@ function theme($hook, $variables = array()) { // If theme() was invoked with a direct theme suggestion like // '#theme' => 'node__article', add it to the suggestions array before // invoking suggestion alter hooks. - if (isset($info['base hook'])) { - $suggestions[] = $hook; + if ($hook != $theme_hooks) { + $suggestions = array_merge($suggestions, (array) $theme_hooks); } + + // Allow suggestions to be altered via hook_theme_suggestions_HOOK_alter(). Drupal::moduleHandler()->alter('theme_suggestions_' . $base_theme_hook, $suggestions, $variables); diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index e09ec99..73c551f 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -62,6 +62,7 @@ function twig_render_template($template_file, $variables) { $current_template = basename($template_file); $suggestions = $variables['theme_hook_suggestions']; $suggestions[] = $variables['theme_hook_original']; + $suggestions = array_unique($suggestions); foreach ($suggestions as &$suggestion) { $template = strtr($suggestion, '_', '-') . $extension; $prefix = ($template == $current_template) ? 'x' : '*';