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";