Commit fcbf91be authored by alexpott's avatar alexpott

Issue #2621874 by czigor, Lendude, dawehner: "Hide empty column" only hides the header

parent 14cfbd4e
......@@ -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.');
}
}
......@@ -108,7 +108,7 @@ display:
default_sort_order: asc
align: ''
separator: ''
empty_column: false
empty_column: true
responsive: ''
default: id
empty_table: true
......
......@@ -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]);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment