MDL-30921 blocks: Added aria-labelledby and aria-label for blocks
authorSam Hemelryk <sam@moodle.com>
Thu, 11 Oct 2012 02:41:05 +0000 (10:41 +0800)
committerSam Hemelryk <sam@moodle.com>
Thu, 1 Nov 2012 21:58:23 +0000 (10:58 +1300)
blocks/moodleblock.class.php
lib/outputcomponents.php
lib/outputrenderers.php

index 814bad6..f9af2b8 100644 (file)
@@ -240,6 +240,9 @@ class block_base {
         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);
index 3cd211a..0be9c09 100644 (file)
@@ -2378,6 +2378,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
      */
index 63e125f..5813af8 100644 (file)
@@ -914,6 +914,12 @@ class core_renderer extends renderer_base {
         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 @@ class core_renderer extends renderer_base {
             $bc->add_class('block_with_controls');
         }
 
-        $skiptitle = strip_tags($bc->title);
+
         if (empty($skiptitle)) {
             $output = '';
             $skipdest = '';
@@ -955,7 +961,11 @@ class core_renderer extends renderer_base {
 
         $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);