diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 2786774..4aebbca 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1264,7 +1264,6 @@ function template_preprocess_table(&$variables) { $variables['rows'][] = array(array( 'data' => $variables['empty'], 'colspan' => $header_count, - 'class' => array('empty', 'message'), )); } @@ -1331,8 +1330,6 @@ 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(); @@ -1346,16 +1343,8 @@ function template_preprocess_table(&$variables) { // Set the attributes array and exclude 'data' and 'no_striping'. $row_attributes = $row; unset($row_attributes['data']); - 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); @@ -1391,7 +1380,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..f30e9a9 100644 --- a/core/modules/system/templates/table.html.twig +++ b/core/modules/system/templates/table.html.twig @@ -58,7 +58,7 @@ {% for cell in header %} - <{{ cell.tag }}{{ cell.attributes }}> + <{{ cell.tag }}{{ cell.attributes.addclass(cell.table_sort ? 'active') }}> {{- cell.content -}} {% endfor %} @@ -69,9 +69,14 @@ {% 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 }}> + <{{ cell.tag }}{{ cell.attributes.addClass(empty ? ['empty', 'message']) }}> {{- cell.content -}} {% endfor %}