From 4284388ba6c7d12b0aa26663d2dd2ceb161c473a Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 20 Nov 2018 12:40:32 +0000 Subject: [PATCH] Issue #2578251 by marthinal, eporama, John Cook, Adita, joe_carvajal, luismagr, Shreya Shetty, Dinesh18, alexpott, Cottser: No results text appears twice --- .../views/templates/views-view.html.twig | 7 ++- .../Functional/ViewsNoResultsBehaviorTest.php | 43 +++++++++++++++++++ .../templates/views/views-view.html.twig | 7 ++- 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 core/modules/views/tests/src/Functional/ViewsNoResultsBehaviorTest.php diff --git a/core/modules/views/templates/views-view.html.twig b/core/modules/views/templates/views-view.html.twig index e81b1ab3dd3..b11724015a0 100644 --- a/core/modules/views/templates/views-view.html.twig +++ b/core/modules/views/templates/views-view.html.twig @@ -51,8 +51,11 @@ {{ exposed }} {{ attachment_before }} - {{ rows }} - {{ empty }} + {% if rows -%} + {{ rows }} + {% elseif empty -%} + {{ empty }} + {% endif %} {{ pager }} {{ attachment_after }} diff --git a/core/modules/views/tests/src/Functional/ViewsNoResultsBehaviorTest.php b/core/modules/views/tests/src/Functional/ViewsNoResultsBehaviorTest.php new file mode 100644 index 00000000000..1a2146d3ab2 --- /dev/null +++ b/core/modules/views/tests/src/Functional/ViewsNoResultsBehaviorTest.php @@ -0,0 +1,43 @@ +enableViewsTestModule(); + $user = $this->createUser([], NULL, TRUE); + $this->drupalLogin($user); + + // Set the Stark theme and use the default templates from views module. + /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */ + $theme_handler = \Drupal::service('theme_handler'); + $theme_handler->install(['stark']); + $this->config('system.theme')->set('default', 'stark')->save(); + } + + /** + * Tests the view with the text. + */ + public function testDuplicateText() { + $output = $this->drupalGet('admin/content'); + $this->assertEqual(1, substr_count($output, 'No content available.'), 'Only one message should be present'); + } + +} diff --git a/core/themes/stable/templates/views/views-view.html.twig b/core/themes/stable/templates/views/views-view.html.twig index 5d372d7a928..2be7d15419b 100644 --- a/core/themes/stable/templates/views/views-view.html.twig +++ b/core/themes/stable/templates/views/views-view.html.twig @@ -49,8 +49,11 @@ {{ exposed }} {{ attachment_before }} - {{ rows }} - {{ empty }} + {% if rows -%} + {{ rows }} + {% elseif empty -%} + {{ empty }} + {% endif %} {{ pager }} {{ attachment_after }}