diff --git a/core/includes/theme.inc b/core/includes/theme.inc index b1f4d36..654803c 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1503,29 +1503,23 @@ function template_preprocess_table(&$variables) { // Format the table columns: if (!empty($variables['colgroups'])) { - foreach ($variables['colgroups'] as $colgroup_key => &$colgroup) { - $colgroup_attributes = new Attribute(); - + foreach ($variables['colgroups'] as &$colgroup) { // Check if we're dealing with a simple or complex column if (isset($colgroup['data'])) { - foreach ($colgroup as $key => $value) { - if ($key == 'data') { - $cols = $value; - } - else { - $colgroup_attributes[$key] = $value; - } - } + $cols = $colgroup['data']; + unset($colgroup['data']); + $colgroup_attributes = $colgroup; } else { $cols = $colgroup; + $colgroup_attributes = array(); } $colgroup = array(); - $colgroup['attributes'] = $colgroup_attributes; + $colgroup['attributes'] = new Attribute($colgroup_attributes); + $colgroup['cols'] = array(); - // Build colgroups and assign attributes + // Build columns. if (is_array($cols) && !empty($cols)) { - $colgroup['cols'] = array(); foreach ($cols as $col_key => $col) { $colgroup['cols'][$col_key]['attributes'] = new Attribute($col); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php index f9b8631..6b9c5ef 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php @@ -133,6 +133,7 @@ function testThemeTableHeaderCellOption() { '#rows' => $rows, ); $this->render($table); + $this->removeWhiteSpace(); $this->assertRaw('111', 'The th and td tags was printed correctly.'); } diff --git a/core/modules/system/templates/table.html.twig b/core/modules/system/templates/table.html.twig index b2161b5..ce69286 100644 --- a/core/modules/system/templates/table.html.twig +++ b/core/modules/system/templates/table.html.twig @@ -40,46 +40,42 @@ {% if caption %} {{ caption }} {% endif %} - {% for colgroup in colgroups -%} - {% if colgroup.cols %} - - {% for col in colgroup.cols -%} - - {%- endfor %} - + {% for colgroup in colgroups %} + {% if colgroup.cols %} + + {% for col in colgroup.cols %} + + {% endfor %} + {% else %} - + {% endif %} - {%- endfor %} - {%- if header %} + {% endfor %} + {% if header %} - {% for cell in header -%} - <{{ cell.tag }}{{ cell.attributes }}> - {{- cell.content -}} - - {%- endfor %} - + {% for cell in header %} + <{{ cell.tag }}{{ cell.attributes }}> + {{- cell.content -}} + + {% endfor %} {% endif %} - {%- if rows %} + {% if rows %} - {%- for row in rows %} - - - {% for cell in row.cells -%} - <{{ cell.tag }}{{ cell.attributes }}> - {{- cell.content -}} - - {%- endfor %} - - + {% for row in rows %} + + {% for cell in row.cells %} + <{{ cell.tag }}{{ cell.attributes }}> + {{- cell.content -}} + + {% endfor %} + {% endfor %} - {% endif %}