diff --git a/core/includes/theme.inc b/core/includes/theme.inc index e44f13d..84e5235 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1601,72 +1601,76 @@ function template_preprocess_table(&$variables) { } } - if (!empty($variables['rows'])) { - $flip = array('even' => 'odd', 'odd' => 'even'); - $class = 'even'; - foreach ($variables['rows'] as $row_key => $row) { - // 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'] : FALSE; - - // Set the attributes array and exclude 'data' and 'no_striping'. - $row_attributes = $row; - unset($row_attributes['data']); - unset($row_attributes['no_striping']); - } - else { - $cells = $row; - $row_attributes = array(); - $no_striping = FALSE; - } + // Rows and footer have the same structure. + $table_parts = array('rows' , 'footer'); + foreach ($table_parts as $table_part) { + if (!empty($variables[$table_part])) { + $flip = array('even' => 'odd', 'odd' => 'even'); + $class = 'even'; + foreach ($variables[$table_part] as $row_key => $row) { + // 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'] : FALSE; + + // Set the attributes array and exclude 'data' and 'no_striping'. + $row_attributes = $row; + unset($row_attributes['data']); + unset($row_attributes['no_striping']); + } + else { + $cells = $row; + $row_attributes = array(); + $no_striping = FALSE; + } - // Add odd/even class. - if (!$no_striping) { - $class = $flip[$class]; - $row_attributes['class'][] = $class; - } + // Add odd/even class. + if (!$no_striping) { + $class = $flip[$class]; + $row_attributes['class'][] = $class; + } - // Build row. - $variables['rows'][$row_key] = array(); - $variables['rows'][$row_key]['attributes'] = new Attribute($row_attributes); - $variables['rows'][$row_key]['cells'] = array(); - if (!empty($cells)) { - foreach ($cells as $col_key => $cell) { - if (!is_array($cell)) { - $cell_content = $cell; - $cell_attributes = array(); - $is_header = FALSE; - } - else { - $cell_content = ''; - if (isset($cell['data'])) { - $cell_content = $cell['data']; - unset($cell['data']); + // Build row. + $variables[$table_part][$row_key] = array(); + $variables[$table_part][$row_key]['attributes'] = new Attribute($row_attributes); + $variables[$table_part][$row_key]['cells'] = array(); + if (!empty($cells)) { + foreach ($cells as $col_key => $cell) { + if (!is_array($cell)) { + $cell_content = $cell; + $cell_attributes = array(); + $is_header = FALSE; } - // Flag the cell as a header or not and remove the flag. - $is_header = !empty($cell['header']); - unset($cell['header']); + else { + $cell_content = ''; + if (isset($cell['data'])) { + $cell_content = $cell['data']; + unset($cell['data']); + } + // Flag the cell as a header or not and remove the flag. + $is_header = !empty($cell['header']); + unset($cell['header']); - $cell_attributes = $cell; + $cell_attributes = $cell; - if (is_array($cell_content)) { - $cell_content = drupal_render($cell_content); + if (is_array($cell_content)) { + $cell_content = drupal_render($cell_content); + } + } + // 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'; + } + // 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]; } - } - // 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'; - } - // 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]; - } - $variables['rows'][$row_key]['cells'][$col_key]['tag'] = $is_header ? 'th' : 'td'; - $variables['rows'][$row_key]['cells'][$col_key]['attributes'] = new Attribute($cell_attributes); - $variables['rows'][$row_key]['cells'][$col_key]['content'] = $cell_content; + $variables[$table_part][$row_key]['cells'][$col_key]['tag'] = $is_header ? 'th' : 'td'; + $variables[$table_part][$row_key]['cells'][$col_key]['attributes'] = new Attribute($cell_attributes); + $variables[$table_part][$row_key]['cells'][$col_key]['content'] = $cell_content; + } } } } @@ -2562,7 +2566,7 @@ function drupal_common_theme() { 'template' => 'breadcrumb', ), 'table' => array( - 'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => FALSE, 'responsive' => TRUE, 'empty' => ''), + 'variables' => array('header' => NULL, 'rows' => NULL, 'footer' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => FALSE, 'responsive' => TRUE, 'empty' => ''), 'template' => 'table', ), 'tablesort_indicator' => array( diff --git a/core/modules/system/templates/table.html.twig b/core/modules/system/templates/table.html.twig index ce69286..04ed606 100644 --- a/core/modules/system/templates/table.html.twig +++ b/core/modules/system/templates/table.html.twig @@ -28,6 +28,16 @@ * - attributes: Any HTML attributes, such as "colspan", to apply to the * table cell. * - content: The string to display in the table cell. + * - footer: Table footer rows. Each row contains the following properties: + * - attributes: HTML attributes to apply to the