From e4a1efcbaa0ed91e125df9b8ca469918508c9d68 Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Tue, 8 Jul 2014 15:17:26 +0800 Subject: [PATCH] MDL-46285 core_renderers: optionally hide user_picture from screen readers --- lib/outputcomponents.php | 5 +++++ lib/outputrenderers.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 76b0c834387..9bf8408af21 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -174,6 +174,11 @@ class user_picture implements renderable { */ public $class = 'userpicture'; + /** + * @var bool Whether to be visible to screen readers. + */ + public $visibletoscreenreaders = true; + /** * User picture constructor. * diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 9da96cb7cbe..b9d228513bc 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2288,6 +2288,7 @@ class core_renderer extends renderer_base { * - popup=false (open in popup) * - alttext=true (add image alt attribute) * - class = image class attribute (default 'userpicture') + * - visibletoscreenreaders=true (whether to be visible to screen readers) * @return string HTML fragment */ public function user_picture(stdClass $user, array $options = null) { @@ -2338,6 +2339,10 @@ class core_renderer extends renderer_base { $src = $userpicture->get_url($this->page, $this); $attributes = array('src'=>$src, 'alt'=>$alt, 'title'=>$alt, 'class'=>$class, 'width'=>$size, 'height'=>$size); + if (!$userpicture->visibletoscreenreaders) { + $attributes['role'] = 'presentation'; + } + // get the image html output fisrt $output = html_writer::empty_tag('img', $attributes); @@ -2360,6 +2365,11 @@ class core_renderer extends renderer_base { } $attributes = array('href'=>$url); + if (!$userpicture->visibletoscreenreaders) { + $attributes['role'] = 'presentation'; + $attributes['tabindex'] = '-1'; + $attributes['aria-hidden'] = 'true'; + } if ($userpicture->popup) { $id = html_writer::random_id('userpicture');