Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-30921 blocks: Added aria-labelledby and aria-label for blocks

  • Loading branch information...
commit 91d941c34c0c5850dbbd6f7d85d4ab26db72880c 1 parent 697f7bd
@samhemelryk samhemelryk authored
View
3  blocks/moodleblock.class.php
@@ -240,6 +240,9 @@ public function get_content_for_output($output) {
if (!$this->hide_header()) {
$bc->title = $this->title;
}
+ if (empty($bc->title)) {
+ $bc->arialabel = new lang_string('pluginname', get_class($this));
+ }
if ($this->page->user_is_editing()) {
$bc->controls = $this->page->blocks->edit_controls($this);
View
6 lib/outputcomponents.php
@@ -2379,6 +2379,12 @@ class block_contents {
public $title = '';
/**
+ * @var string The label to use when the block does not, or will not have a visible title.
+ * You should never set this as well as title... it will just be ignored.
+ */
+ public $arialabel = '';
+
+ /**
* @var string HTML for the content
*/
public $content = '';
View
14 lib/outputrenderers.php
@@ -914,6 +914,12 @@ public function block(block_contents $bc, $region) {
if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
$bc->collapsible = block_contents::NOT_HIDEABLE;
}
+ $skiptitle = strip_tags($bc->title);
+ if ($bc->blockinstanceid && !empty($skiptitle)) {
+ $bc->attributes['aria-labelledby'] = 'instance-'.$bc->blockinstanceid.'-header';
+ } else if (!empty($bc->arialabel)) {
+ $bc->attributes['aria-label'] = $bc->arialabel;
+ }
if ($bc->collapsible == block_contents::HIDDEN) {
$bc->add_class('hidden');
}
@@ -921,7 +927,7 @@ public function block(block_contents $bc, $region) {
$bc->add_class('block_with_controls');
}
- $skiptitle = strip_tags($bc->title);
+
if (empty($skiptitle)) {
$output = '';
$skipdest = '';
@@ -955,7 +961,11 @@ protected function block_header(block_contents $bc) {
$title = '';
if ($bc->title) {
- $title = html_writer::tag('h2', $bc->title, null);
+ $attributes = array();
+ if ($bc->blockinstanceid) {
+ $attributes['id'] = 'instance-'.$bc->blockinstanceid.'-header';
+ }
+ $title = html_writer::tag('h2', $bc->title, $attributes);
}
$controlshtml = $this->block_controls($bc->controls);
Please sign in to comment.
Something went wrong with that request. Please try again.