mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-68343 output: fix html table structure
A <th> that contains no text may result in cells with missing or incorrect header information. WAVE advises that we should make a cell a <td> rather than a <th> 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 <th>
This commit is contained in:
parent
788dfb9c7d
commit
d28b4ec326
@ -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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user