From 582584e4991a11bde825c0c6a5949d4808609917 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 6 Jul 2020 23:06:02 +0100 Subject: [PATCH] =?UTF-8?q?Issue=20#3149930=20by=20Lendude,=20ravi.shankar?= =?UTF-8?q?,=20Bob=C3=ADk,=20dww,=20joaomachado,=20alexpott,=20lauriii:=20?= =?UTF-8?q?Views=20table=20settings=20exposes=20"Details"=20field=20even?= =?UTF-8?q?=20when=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 5bd974ae17b914a9c4563d7077f721bbff2df44d) --- .../src/Functional/Plugin/StyleTableTest.php | 2 ++ core/modules/views/views.theme.inc | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php b/core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php index bcd8cf85660..e81c213fde9 100644 --- a/core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php @@ -211,6 +211,8 @@ class StyleTableTest extends ViewTestBase { // Ensure that we don't find the caption containing unsafe markup. $this->assertNoRaw($unsafe_markup, "Didn't find caption containing unsafe markup."); + // Ensure that the summary isn't shown. + $this->assertEmpty($this->xpath('//caption/details')); // Ensure that all expected captions are found. foreach ($expected_captions as $raw_caption) { diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index ba955976088..019899ada4a 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -664,20 +664,22 @@ function template_preprocess_views_view_table(&$variables) { // variables, although core templates now all use 'summary_element' instead. $variables['summary'] = $handler->options['summary']; $variables['description'] = $handler->options['description']; - $variables['summary_element'] = [ - '#type' => 'details', - '#title' => $handler->options['summary'], - // To ensure that the description is properly escaped during rendering, use - // an 'inline_template' to let Twig do its magic, instead of 'markup'. - 'description' => [ - '#type' => 'inline_template', - '#template' => '{{ description }}', - '#context' => [ - 'description' => $handler->options['description'], + if (!empty($handler->options['summary']) || !empty($handler->options['description'])) { + $variables['summary_element'] = [ + '#type' => 'details', + '#title' => $handler->options['summary'], + // To ensure that the description is properly escaped during rendering, + // use an 'inline_template' to let Twig do its magic, instead of 'markup'. + 'description' => [ + '#type' => 'inline_template', + '#template' => '{{ description }}', + '#context' => [ + 'description' => $handler->options['description'], + ], ], - ], - ]; - $variables['caption_needed'] |= !empty($variables['summary']) || !empty($variables['description']); + ]; + $variables['caption_needed'] = TRUE; + } $variables['responsive'] = FALSE; // If the table has headers and it should react responsively to columns hidden