diff --git a/core/includes/theme.inc b/core/includes/theme.inc index b21bfb1..8a77595 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1464,6 +1464,7 @@ function drupal_pre_render_table(array $element) { * can be either a localized string or an associative array with the * following keys: * - "data": The localized summary information of the table column. + * - "header": Indicates this cell is a header. * - Any HTML attributes, such as "colspan", to apply to the column footer * cell. * - attributes: An array of HTML attributes to apply to the table tag. @@ -1618,8 +1619,9 @@ function template_preprocess_table(&$variables) { $cell_content = $cell['data']; unset($cell['data']); } - // Flag the cell as a footer or not and remove the flag. - unset($cell['footer']); + // Flag the cell as a header or not and remove the flag. + $is_header = isset($cell['header']) ? $cell['header'] : TRUE; + unset($cell['header']); // Track responsive classes for each column as needed. Only the footer // cells for a column are marked up with the responsive classes by a @@ -1640,7 +1642,7 @@ function template_preprocess_table(&$variables) { $cell_attributes = new Attribute($cell); } $variables['footer'][$col_key] = array(); - $variables['footer'][$col_key]['tag'] = 'td'; + $variables['header'][$col_key]['tag'] = $is_header ? 'th' : 'td'; $variables['footer'][$col_key]['attributes'] = $cell_attributes; $variables['footer'][$col_key]['content'] = $cell_content; } diff --git a/core/modules/system/templates/table.html.twig b/core/modules/system/templates/table.html.twig index 4881e46..884349a 100644 --- a/core/modules/system/templates/table.html.twig +++ b/core/modules/system/templates/table.html.twig @@ -17,10 +17,6 @@ * - content: A localized string for the title of the column. * - field: Field name (required for column sorting). * - sort: Default sort order for this column ("asc" or "desc"). - * - header: Table header cells. Each cell contains the following properties: - * - attributes: HTML attributes to apply to the tag. - * - content: A localized string for the title of the column. - * - field: Field name (required for column sorting). * - sticky: A flag indicating whether to use a "sticky" table header. * - rows: Table rows. Each row contains the following properties: * - attributes: HTML attributes to apply to the tag. @@ -32,6 +28,11 @@ * - 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 cells. Each cell contains the following properties: + * - tag: The HTML tag name to use; either TH or TD. + * - attributes: HTML attributes to apply to the tag. + * - content: A localized string for the title of the column. + * - field: Field name (required for column sorting). * - empty: The message to display in an extra row if table does not have * any rows. * @@ -66,17 +67,6 @@ {% endif %} - {% if footer %} - - - {% for cell in footer %} - - {{- cell.content -}} - - {% endfor %} - - - {% endif %} {% if rows %} {% for row in rows %} @@ -90,4 +80,15 @@ {% endfor %} {% endif %} + {% if footer %} + + + {% for cell in footer %} + <{{ cell.tag }}{{ cell.attributes }}> + {{- cell.content -}} + + {% endfor %} + + + {% endif %}