diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 4230087..9886e67 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1549,7 +1549,6 @@ function template_preprocess_table(&$variables) { $responsive_classes = array(); // Format the table header: - $ts = array(); if (!empty($variables['header'])) { $ts = tablesort_init($variables['header']); @@ -1596,6 +1595,55 @@ function template_preprocess_table(&$variables) { $variables['header'][$col_key]['attributes'] = $cell_attributes; $variables['header'][$col_key]['content'] = $cell_content; } + + + // Format the table footer: + if (!empty($variables['footer'])) { + $ts = tablesort_init($variables['footer']); + + foreach ($variables['footer'] as $col_key => $cell) { + if (!is_array($cell)) { + $cell_content = $cell; + $cell_attributes = new Attribute(); + $is_footer = TRUE; + } + else { + $cell_content = ''; + if (isset($cell['data'])) { + $cell_content = $cell['data']; + unset($cell['data']); + } + // Flag the cell as a footer or not and remove the flag. + $is_footer = isset($cell['footer']) ? $cell['footer'] : TRUE; + unset($cell['footer']); + + // Track responsive classes for each column as needed. Only the footer + // cells for a column are marked up with the responsive classes by a + // module developer or themer. The responsive classes on the footer cells + // 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; + } + elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) { + $responsive_classes[$col_key] = RESPONSIVE_PRIORITY_LOW; + } + } + + if (is_array($cell_content)) { + $cell_content = drupal_render($cell_content); + } + + tablesort_footer($cell_content, $cell, $variables['footer'], $ts); + + // tablesort_footer() removes the 'sort' and 'field' keys. + $cell_attributes = new Attribute($cell); + } + $variables['footer'][$col_key] = array(); + $variables['footer'][$col_key]['tag'] = 'td'; + $variables['footer'][$col_key]['attributes'] = $cell_attributes; + $variables['footer'][$col_key]['content'] = $cell_content; + } } if (!empty($variables['rows'])) { @@ -2553,7 +2601,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, 'footer' => NULL, 'rows' => 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..6aec2b6 100644 --- a/core/modules/system/templates/table.html.twig +++ b/core/modules/system/templates/table.html.twig @@ -78,4 +78,16 @@ {% endfor %} {% endif %} + + {% if header %} +
+