diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 0a76479..5f8914f 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/modules/views/src/Tests/ViewsThemeIntegrationTest.php b/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php index e368c84..3b0e14f 100644 --- a/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php +++ b/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php @@ -81,4 +81,29 @@ public function testThemedViewPage() { $this->assertRaw("test_basetheme_views_post_render", "Views title changed by test_basetheme.test_basetheme_views_post_render"); } + /** + * Tests the views theme suggestions in debug mode. + */ + public function testThemeSuggestionsInDebug() { + $parameters = $this->container->getParameter('twig.config'); + $parameters['debug'] = TRUE; + $this->setContainerParameter('twig.config', $parameters); + $this->rebuildContainer(); + $this->resetAll(); + + $build = [ + '#type' => 'view', + '#name' => 'test_page_display', + '#display_id' => 'default', + '#arguments' => array(), + ]; + + $output = drupal_render($build, TRUE); + + $this->assertTrue(strpos($output, '* views-view--test-page-display--default.html.twig') !== FALSE); + $this->assertTrue(strpos($output, '* views-view--default.html.twig') !== FALSE); + $this->assertTrue(strpos($output, '* views-view--test-page-display.html.twig') !== FALSE); + $this->assertTrue(strpos($output, 'x views-view.html.twig') !== FALSE); + } + } 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' : '*';