diff --git a/core/includes/theme.inc b/core/includes/theme.inc index c726d07..adfe636 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1244,7 +1244,6 @@ function template_preprocess_table(&$variables) { $variables['rows'][] = array(array( 'data' => $variables['empty'], 'colspan' => $header_count, - 'class' => array('empty', 'message'), )); } @@ -1311,17 +1310,14 @@ function template_preprocess_table(&$variables) { $sections = array('rows' , 'footer'); foreach ($sections as $section) { if (!empty($variables[$section])) { - $flip = array('even' => 'odd', 'odd' => 'even'); - $class = 'even'; foreach ($variables[$section] as $row_key => $row) { $cells = $row; $row_attributes = array(); - $no_striping = $section === 'footer'; // Check if we're dealing with a simple or complex row if (isset($row['data'])) { $cells = $row['data']; - $no_striping = isset($row['no_striping']) ? $row['no_striping'] : $no_striping; + $variables['no_striping'] = isset($row['no_striping']) ? $row['no_striping'] : FALSE; // Set the attributes array and exclude 'data' and 'no_striping'. $row_attributes = $row; @@ -1329,13 +1325,6 @@ function template_preprocess_table(&$variables) { unset($row_attributes['no_striping']); } - // Add odd/even class. - if (!$no_striping) { - $class = $flip[$class]; - $row_attributes['class'][] = $class; - } - - // Build row. $variables[$section][$row_key] = array(); $variables[$section][$row_key]['attributes'] = new Attribute($row_attributes); @@ -1371,7 +1360,7 @@ function template_preprocess_table(&$variables) { } // Add active class if needed for sortable tables. if (isset($variables['header'][$col_key]['data']) && $variables['header'][$col_key]['data'] == $ts['name'] && !empty($variables['header'][$col_key]['field'])) { - $cell_attributes['class'][] = 'active'; + $variables[$section][$row_key]['cells'][$col_key]['table_sort'] = TRUE; } // Copy RESPONSIVE_PRIORITY_LOW/RESPONSIVE_PRIORITY_MEDIUM // class from header to cell as needed. diff --git a/core/modules/system/templates/table.html.twig b/core/modules/system/templates/table.html.twig index 9c1cb05..89cd41a 100644 --- a/core/modules/system/templates/table.html.twig +++ b/core/modules/system/templates/table.html.twig @@ -58,7 +58,12 @@ {% for cell in header %} - <{{ cell.tag }}{{ cell.attributes }}> + {% + set cell_classes = [ + cell.table_sort ? 'active', + ] + %} + <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}> {{- cell.content -}} {% endfor %} @@ -69,9 +74,20 @@ {% if rows %} {% for row in rows %} - + {% + set row_classes = [ + not no_striping ? cycle(['odd', 'even'], loop.index0), + ] + %} + {% for cell in row.cells %} - <{{ cell.tag }}{{ cell.attributes }}> + {% + set cell_classes = [ + empty ? 'empty', + empty ? 'message', + ] + %} + <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}> {{- cell.content -}} {% endfor %}