Skip to content

Instantly share code, notes, and snippets.

@jacine
Created August 23, 2011 01:34
Show Gist options
  • Save jacine/1164095 to your computer and use it in GitHub Desktop.
Save jacine/1164095 to your computer and use it in GitHub Desktop.
Add ARIA roles to blocks
<?php
/**
* Implements template_preprocess_block().
*/
function THEME_preprocess_block(&$vars) {
$roles = array(
'complementary' => array(
'aggregator',
'help',
'locale',
'poll',
'profile',
'node' => array('syndicate'),
'system' => array('powered-by', 'help'),
'user' => array('new', 'online'),
),
'navigation' => array(
'blog',
'book',
'comment',
'forum',
'menu',
'menu_block',
'node' => array('recent'),
'shortcut',
'statistics',
'system' => array_keys(menu_list_system_menus()),
),
'search' => array(
'search',
),
'form' => array(
'user' => array('login'),
),
);
foreach ($roles as $role => $module) {
if (!is_array($role) && in_array($vars['block']->module, $module)) {
$vars['attributes_array']['role'] = "$role";
}
elseif (is_array($role)) {
foreach ($role as $module => $delta) {
if ($vars['block']->module == $module && in_array($vars['block']->delta, $delta)) {
$vars['attributes_array']['role'] = "$role";
}
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment