From fcbf91be098f6bad983628db5919f29d5da6fead Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 21 Dec 2015 13:09:43 +0000 Subject: [PATCH] Issue #2621874 by czigor, Lendude, dawehner: "Hide empty column" only hides the header --- .../views/src/Tests/Plugin/StyleTableTest.php | 19 +++++++++++++++++++ .../test_views/views.view.test_table.yml | 2 +- core/modules/views/views.theme.inc | 6 +++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/core/modules/views/src/Tests/Plugin/StyleTableTest.php b/core/modules/views/src/Tests/Plugin/StyleTableTest.php index 0c423a9a6070..5358b2d6d1a6 100644 --- a/core/modules/views/src/Tests/Plugin/StyleTableTest.php +++ b/core/modules/views/src/Tests/Plugin/StyleTableTest.php @@ -136,4 +136,23 @@ public function testNumericFieldVisible() { $this->assertTrue(count($result), 'Ensure that the baby\'s age is shown'); } + /** + * Test that empty columns are hidden when empty_column is set. + */ + public function testEmptyColumn() { + // Empty the 'job' data. + \Drupal::database()->update('views_test_data') + ->fields(['job' => '']) + ->execute(); + + $this->drupalGet('test-table'); + + // Test that only one of the job columns still shows. + $result = $this->xpath('//thead/tr/th/a[text()="Job"]'); + $this->assertEqual(count($result), 1, 'Ensure that empty column header is hidden.'); + + $result = $this->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job-1 ")]'); + $this->assertEqual(count($result), 0, 'Ensure the empty table cells are hidden.'); + } + } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_table.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_table.yml index 698e072e3f6d..b391efc0b8ca 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_table.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_table.yml @@ -108,7 +108,7 @@ display: default_sort_order: asc align: '' separator: '' - empty_column: false + empty_column: true responsive: '' default: id empty_table: true diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index a802ff6846dd..12e2b5fb41ba 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -552,13 +552,13 @@ function template_preprocess_views_view_table(&$variables) { if (!empty($options['info'][$field]['empty_column'])) { $empty = TRUE; foreach ($variables['rows'] as $columns) { - $empty &= empty($columns[$column]); + $empty &= empty($columns['columns'][$column]['content']); } if ($empty) { foreach ($variables['rows'] as &$column_items) { - unset($column_items[$column]); - unset($variables['header'][$column]); + unset($column_items['columns'][$column]); } + unset($variables['header'][$column]); } } } -- GitLab