Improve aria-hidden handling in the icon and img view helper

This commit is contained in:
Johannes Meyer 2015-03-03 14:35:41 +01:00
parent d9fdcf036b
commit c2339d156b
1 changed files with 6 additions and 4 deletions

View File

@ -53,11 +53,12 @@ $this->addHelperFunction('img', function ($url, $params = null, array $propertie
$properties['alt'] = '';
}
$ariaHidden = array_key_exists('aria-hidden', $properties) ? $properties['aria-hidden'] : null;
if (array_key_exists('title', $properties)) {
if (! array_key_exists('aria-label', $properties) && !array_key_exists('aria-hidden', $properties)) {
if (! array_key_exists('aria-label', $properties) && $ariaHidden !== 'true') {
$properties['aria-label'] = $properties['title'];
}
} elseif (! array_key_exists('aria-hidden', $properties)) {
} elseif ($ariaHidden === null) {
$properties['aria-hidden'] = 'true';
}
@ -79,14 +80,15 @@ $this->addHelperFunction('icon', function ($img, $title = null, array $propertie
return $view->img('img/icons/' . $img, $properties);
}
$ariaHidden = array_key_exists('aria-hidden', $properties) ? $properties['aria-hidden'] : null;
if ($title !== null) {
$properties['role'] = 'img';
$properties['title'] = $title;
if (! array_key_exists('aria-label', $properties) && !array_key_exists('aria-hidden', $properties)) {
if (! array_key_exists('aria-label', $properties) && $ariaHidden !== 'true') {
$properties['aria-label'] = $title;
}
} elseif (! array_key_exists('aria-hidden', $properties)) {
} elseif ($ariaHidden === null) {
$properties['aria-hidden'] = 'true';
}