From d28b4ec3264148a652639b8ca416ba853b1db3f9 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Mon, 6 Apr 2020 17:03:51 +1000 Subject: [PATCH] MDL-68343 output: fix html table structure A that contains no text may result in cells with missing or incorrect header information. WAVE advises that we should make a cell a rather than a if the cell must remain empty (such as the top-left cell in a data table). Also note that the scope attribute is only valid for --- lib/outputcomponents.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index f6d432d2a0b..490e3b488e2 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -2207,8 +2207,9 @@ class html_writer { $heading->header = true; } - if ($heading->header && empty($heading->scope)) { - $heading->scope = 'col'; + $tagtype = 'td'; + if ($heading->header && (string)$heading->text != '') { + $tagtype = 'th'; } $heading->attributes['class'] .= ' header c' . $key; @@ -2224,16 +2225,15 @@ class html_writer { $heading->attributes['class'] .= ' ' . $table->colclasses[$key]; } $heading->attributes['class'] = trim($heading->attributes['class']); - $attributes = array_merge($heading->attributes, array( - 'style' => $table->align[$key] . $table->size[$key] . $heading->style, - 'scope' => $heading->scope, - 'colspan' => $heading->colspan, - )); + $attributes = array_merge($heading->attributes, [ + 'style' => $table->align[$key] . $table->size[$key] . $heading->style, + 'colspan' => $heading->colspan, + ]); - $tagtype = 'td'; - if ($heading->header === true) { - $tagtype = 'th'; + if ($tagtype == 'th') { + $attributes['scope'] = !empty($heading->scope) ? $heading->scope : 'col'; } + $output .= html_writer::tag($tagtype, $heading->text, $attributes) . "\n"; } $output .= html_writer::end_tag('tr') . "\n";