diff --git a/core/includes/theme.inc b/core/includes/theme.inc index dd50e62..32b1e9f 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1482,6 +1482,24 @@ function drupal_pre_render_table(array $element) { * narrow viewports to save horizontal space. * - Any HTML attributes, such as "colspan", to apply to the column header * cell. + * - footer: An array containing the table footers. Each element of the array + * can be either a localized string or an associative array with the + * following keys: + * - "data": The localized summary information of the table column. + * - Any HTML attributes, such as "colspan", to apply to the column footer + * cell. + * Here's an example for $footer: + * @code + * // simple footer + * $footer = array('footer cell1', 'footer cell2', 'footer cell3'); + * // complex footer + * $footer = array( + * 'data' => array( + * array('data' => t('footer cell1'), 'class' => 'footer-cell-1'), + * array('data' => t('footer cell2'), 'colspan' => 2)), + * 'class' => 'footer' + * ); + * @endcode * - rows: An array of table rows. Every row is an array of cells, or an * associative array with the following keys: * - "data": an array of cells @@ -1545,6 +1563,7 @@ function drupal_pre_render_table(array $element) { */ function theme_table($variables) { $header = $variables['header']; + $footer = $variables['footer']; $rows = $variables['rows']; $attributes = $variables['attributes']; $caption = $variables['caption']; @@ -1656,6 +1675,40 @@ function theme_table($variables) { $ts = array(); } + if (count($footer)) { + // Check if we're dealing with a simple or complex row + if (isset($footer['data'])) { + $cells = $footer['data']; + // Set the attributes array and exclude 'data' + $attributes = $footer; + unset($attributes['data']); + } + else { + $cells = $footer; + $attributes = array(); + } + + // HTML requires that the tfoot tag has tr tags in it followed by tbody + // tags. Using ternary operator to check and see if we have any rows. + $output .= (count($rows) ? ' ' : ' '); + $i = 0; + foreach ($cells as $cell) { + // Copy RESPONSIVE_PRIORITY_LOW/RESPONSIVE_PRIORITY_MEDIUM + // class from header to cell as needed. + if (isset($responsive[$i])) { + if (is_array($cell)) { + $cell['class'][] = $responsive[$i]; + } + else { + $cell = array('data' => $cell, 'class' => $responsive[$i]); + } + } + $output .= _theme_table_cell($cell); + } + + // Using ternary operator to close the tags based on whether or not there are rows + $output .= (count($rows) ? " \n" : "\n"); + } // Format the table rows: if (count($rows)) { $output .= "\n"; @@ -2593,7 +2646,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' => ''), ), 'tablesort_indicator' => array( 'variables' => array('style' => NULL),