From 5fe283cac660396dfa5aa42ca93a4d6fc554b097 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 8 Jul 2014 11:35:20 +0100 Subject: [PATCH] Issue #2296859 by Mark Carver: Fixed [regression] Responsive classes not always added to table rows. --- core/includes/theme.inc | 19 +++++++++++++++---- .../system/src/Tests/Theme/TableTest.php | 5 ++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index b37eb97fa05f..7cb205c1635f 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1561,7 +1561,13 @@ function template_preprocess_table(&$variables) { if (!empty($variables['header'])) { $ts = tablesort_init($variables['header']); + // Use a separate index with responsive classes as headers + // may be associative. + $responsive_index = -1; foreach ($variables['header'] as $col_key => $cell) { + // Increase the responsive index. + $responsive_index++; + if (!is_array($cell)) { $cell_content = $cell; $cell_attributes = new Attribute(); @@ -1583,10 +1589,10 @@ function template_preprocess_table(&$variables) { // must be transferred to the content cells. if (!empty($cell['class']) && is_array($cell['class'])) { if (in_array(RESPONSIVE_PRIORITY_MEDIUM, $cell['class'])) { - $responsive_classes[$col_key] = RESPONSIVE_PRIORITY_MEDIUM; + $responsive_classes[$responsive_index] = RESPONSIVE_PRIORITY_MEDIUM; } elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) { - $responsive_classes[$col_key] = RESPONSIVE_PRIORITY_LOW; + $responsive_classes[$responsive_index] = RESPONSIVE_PRIORITY_LOW; } } @@ -1637,7 +1643,12 @@ function template_preprocess_table(&$variables) { $variables['rows'][$row_key]['attributes'] = new Attribute($row_attributes); $variables['rows'][$row_key]['cells'] = array(); if (!empty($cells)) { + // Reset the responsive index. + $responsive_index = -1; foreach ($cells as $col_key => $cell) { + // Increase the responsive index. + $responsive_index++; + if (!is_array($cell)) { $cell_content = $cell; $cell_attributes = array(); @@ -1665,8 +1676,8 @@ function template_preprocess_table(&$variables) { } // Copy RESPONSIVE_PRIORITY_LOW/RESPONSIVE_PRIORITY_MEDIUM // class from header to cell as needed. - if (isset($responsive_classes[$col_key])) { - $cell_attributes['class'][] = $responsive_classes[$col_key]; + if (isset($responsive_classes[$responsive_index])) { + $cell_attributes['class'][] = $responsive_classes[$responsive_index]; } $variables['rows'][$row_key]['cells'][$col_key]['tag'] = $is_header ? 'th' : 'td'; diff --git a/core/modules/system/src/Tests/Theme/TableTest.php b/core/modules/system/src/Tests/Theme/TableTest.php index 4b59aa89ebac..60c28c8f3f6b 100644 --- a/core/modules/system/src/Tests/Theme/TableTest.php +++ b/core/modules/system/src/Tests/Theme/TableTest.php @@ -188,8 +188,11 @@ class TableTest extends DrupalUnitTestBase { */ public function testThemeTableResponsivePriority() { $header = array( - array('data' => 1, 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), + // Test associative header indices. + 'associative_key' => array('data' => 1, 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), + // Test non-associative header indices. array('data' => 2, 'class' => array(RESPONSIVE_PRIORITY_LOW)), + // Test no responsive priorities. array('data' => 3), ); $rows = array(array(4, 5, 6));