diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8c947e2..b8875e2 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -227,6 +227,8 @@ function _theme($hook, $variables = array()) { /** @var \Drupal\Core\Utility\ThemeRegistry $theme_registry */ $theme_registry = \Drupal::service('theme.registry')->getRuntime(); + $theme_hooks = $hook; + // If an array of hook candidates were passed, use the first one that has an // implementation. if (is_array($hook)) { @@ -314,6 +316,10 @@ 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 ($hook != $theme_hooks) { + $suggestions = array_merge($suggestions, (array) $theme_hooks); + $suggestions = array_reverse($suggestions); + } if (isset($info['base hook'])) { $suggestions[] = $hook; } diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index cd84b33..07a299f 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -93,6 +93,7 @@ function twig_render_template($template_file, $variables) { if (strpos($variables['theme_hook_original'], '__') === FALSE) { $suggestions[] = $variables['theme_hook_original']; } + $suggestions = array_unique($suggestions); foreach ($suggestions as &$suggestion) { $template = strtr($suggestion, '_', '-') . $extension; $prefix = ($template == $current_template) ? 'x' : '*';