Skip to content

Commit 69937f4

Browse files
committed
Issue #3149930 by Lendude, ravi.shankar, Bobík, dww, joaomachado, alexpott, lauriii: Views table settings exposes "Details" field even when empty
(cherry picked from commit 5bd974ae17b914a9c4563d7077f721bbff2df44d)
1 parent aad10aa commit 69937f4

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

modules/views/tests/src/Functional/Plugin/StyleTableTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ public function testGrouping() {
211211

212212
// Ensure that we don't find the caption containing unsafe markup.
213213
$this->assertNoRaw($unsafe_markup, "Didn't find caption containing unsafe markup.");
214+
// Ensure that the summary isn't shown.
215+
$this->assertEmpty($this->xpath('//caption/details'));
214216

215217
// Ensure that all expected captions are found.
216218
foreach ($expected_captions as $raw_caption) {

modules/views/views.theme.inc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -664,20 +664,22 @@ function template_preprocess_views_view_table(&$variables) {
664664
// variables, although core templates now all use 'summary_element' instead.
665665
$variables['summary'] = $handler->options['summary'];
666666
$variables['description'] = $handler->options['description'];
667-
$variables['summary_element'] = [
668-
'#type' => 'details',
669-
'#title' => $handler->options['summary'],
670-
// To ensure that the description is properly escaped during rendering, use
671-
// an 'inline_template' to let Twig do its magic, instead of 'markup'.
672-
'description' => [
673-
'#type' => 'inline_template',
674-
'#template' => '{{ description }}',
675-
'#context' => [
676-
'description' => $handler->options['description'],
667+
if (!empty($handler->options['summary']) || !empty($handler->options['description'])) {
668+
$variables['summary_element'] = [
669+
'#type' => 'details',
670+
'#title' => $handler->options['summary'],
671+
// To ensure that the description is properly escaped during rendering,
672+
// use an 'inline_template' to let Twig do its magic, instead of 'markup'.
673+
'description' => [
674+
'#type' => 'inline_template',
675+
'#template' => '{{ description }}',
676+
'#context' => [
677+
'description' => $handler->options['description'],
678+
],
677679
],
678-
],
679-
];
680-
$variables['caption_needed'] |= !empty($variables['summary']) || !empty($variables['description']);
680+
];
681+
$variables['caption_needed'] = TRUE;
682+
}
681683

682684
$variables['responsive'] = FALSE;
683685
// If the table has headers and it should react responsively to columns hidden

0 commit comments

Comments
 (0)