Last active
April 13, 2018 13:03
-
-
Save peteboere/7560963 to your computer and use it in GitHub Desktop.
Drupal theme overrides for better accessibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
theme_image() override. | |
*/ | |
function THEME_image($vars) | |
{ | |
// [Accessibility] Images must always have an alt attribute. | |
if (! isset($vars['alt'])) { | |
$vars['alt'] = ''; | |
} | |
return theme_image($vars); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
theme_link() override. | |
*/ | |
function THEME_link($vars) | |
{ | |
$attrs =& $vars['options']['attributes']; | |
// [Accessibility] Remove href attribute for links that are the current page. | |
if (!(isset($attrs['class']) && in_array('active', $attrs['class']))) { | |
$url = check_plain(url($vars['path'], $vars['options'])); | |
$attrs['href'] = $url; | |
} | |
// [Accessibility] Avoid empty title attributes and 'parrot' tooltips. | |
if ( | |
isset($attrs['title']) && | |
(! strlen($attrs['title']) || $attrs['title'] == $vars['text']) | |
) { | |
unset($attrs['title']); | |
} | |
return '<a' . drupal_attributes($vars['options']['attributes']) . '>' . | |
($vars['options']['html'] ? $vars['text'] : check_plain($vars['text'])) . | |
'</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment