MDL-67683 output: Make block regions unique
Unique labels for the block regions: * `side-pre` blocks - "Blocks" * `side-post` blocks - "Supplementary blocks" * `content` blocks - "Main content blocks" Blocks in the main content region (div role="main") should not also be in an <aside> as it is a top-level landmark.
This commit is contained in:
@@ -222,6 +222,8 @@ $string['block'] = 'Block';
|
||||
$string['blockconfiga'] = 'Configuring a {$a} block';
|
||||
$string['blockconfigbad'] = 'This block has not been implemented correctly and thus cannot provide a configuration interface.';
|
||||
$string['blocks'] = 'Blocks';
|
||||
$string['blocks_main'] = 'Main content blocks';
|
||||
$string['blocks_supplementary'] = 'Supplementary blocks';
|
||||
$string['blocksaddedit'] = 'Add/Edit blocks';
|
||||
$string['blockseditoff'] = 'Blocks editing off';
|
||||
$string['blocksediton'] = 'Blocks editing on';
|
||||
|
||||
@@ -3817,6 +3817,7 @@ EOD;
|
||||
*/
|
||||
public function blocks($region, $classes = [], $tag = 'aside', $fakeblocksonly = false) {
|
||||
$displayregion = $this->page->apply_theme_region_manipulations($region);
|
||||
$headingid = $displayregion . '-block-region-heading';
|
||||
$classes = (array)$classes;
|
||||
$classes[] = 'block-region';
|
||||
$attributes = [
|
||||
@@ -3824,12 +3825,23 @@ EOD;
|
||||
'class' => join(' ', $classes),
|
||||
'data-blockregion' => $displayregion,
|
||||
'data-droptarget' => '1',
|
||||
'aria-labelledby' => $headingid,
|
||||
];
|
||||
// Generate an appropriate heading to uniquely identify the block region.
|
||||
$blocksheading = match ($displayregion) {
|
||||
'side-post' => get_string('blocks_supplementary'),
|
||||
'content' => get_string('blocks_main'),
|
||||
default => get_string('blocks'),
|
||||
};
|
||||
$content = html_writer::tag('h2', $blocksheading, ['class' => 'visually-hidden', 'id' => $headingid]);
|
||||
if ($this->page->blocks->region_has_content($displayregion, $this)) {
|
||||
$content = html_writer::tag('h2', get_string('blocks'), ['class' => 'visually-hidden']) .
|
||||
$this->blocks_for_region($displayregion, $fakeblocksonly);
|
||||
} else {
|
||||
$content = html_writer::tag('h2', get_string('blocks'), ['class' => 'visually-hidden']);
|
||||
$content .= $this->blocks_for_region($displayregion, $fakeblocksonly);
|
||||
}
|
||||
// Given that <aside> has a default role of a complementary landmark and is supposed to be a top-level landmark,
|
||||
// blocks rendered as part of the main content should not have a complementary role and should be rendered in a more generic
|
||||
// container.
|
||||
if ($displayregion === 'content' && $tag === 'aside') {
|
||||
$tag = 'section';
|
||||
}
|
||||
return html_writer::tag($tag, $content, $attributes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user