diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index f247d26..df30c5d 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -420,6 +420,11 @@ function aggregator_block_view($delta = '') { if (count($items) > 0) { $block['content'] = theme('item_list', array('items' => $items)) . $read_more; } + + // Add in the WAI-ARIA role if required. + if (isset($block['subject'])) { + $block['attributes']['role'] = 'complementary'; + } return $block; } } diff --git a/modules/block/block.api.php b/modules/block/block.api.php index d33f594..72c950d 100644 --- a/modules/block/block.api.php +++ b/modules/block/block.api.php @@ -197,6 +197,8 @@ function hook_block_save($delta = '', $edit = array()) { * have a default title, this should be set to NULL. * - content: The content of the block's body. This may be a renderable array * (preferable) or a string containing rendered HTML content. + * - attributes: (optional) Additional attributes array to apply to the block + * when rendered. * * For a detailed usage example, see block_example.module. * @@ -211,6 +213,7 @@ function hook_block_view($delta = '') { switch ($delta) { case 'syndicate': $block['subject'] = t('Syndicate'); + $block['attributes']['class'][] = 'syndicate'; $block['content'] = array( '#theme' => 'feed_icon', '#url' => 'rss.xml', @@ -221,6 +224,7 @@ function hook_block_view($delta = '') { case 'recent': if (user_access('access content')) { $block['subject'] = t('Recent content'); + $block['attributes']['class'][] = 'recentcontent'; if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) { $block['content'] = array( '#theme' => 'node_recent_block', @@ -251,6 +255,7 @@ function hook_block_view($delta = '') { * - content: Either a string or a renderable array representing the content * of the block. You should check that the content is an array before trying * to modify parts of the renderable structure. + * - attributes: An array of attributes to apply to the block. * @param $block * The block object, as loaded from the database, having the main properties: * - module: The name of the module that defined the block. diff --git a/modules/block/block.module b/modules/block/block.module index 920090f..5a595ba 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -930,8 +930,6 @@ function template_preprocess_block(&$variables) { // Create the $content variable that templates expect. $variables['content'] = $variables['elements']['#children']; - $variables['classes_array'][] = drupal_html_class('block-' . $variables['block']->module); - // Add default class for block content. $variables['content_attributes_array']['class'][] = 'content'; @@ -947,8 +945,24 @@ function template_preprocess_block(&$variables) { // hyphens to underscores in block deltas for the theme suggestions. $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module . '__' . strtr($variables['block']->delta, '-', '_'); - // Create a valid HTML ID and make sure it is unique. - $variables['block_html_id'] = drupal_html_id('block-' . $variables['block']->module . '-' . $variables['block']->delta); + // Construct the attributes array for the rendered block. + $attributes = isset($variables['block']->attributes) ? $variables['block']->attributes : array(); + + // Retrieve the ID for the block. + if (!isset($attributes['id'])) { + // Create a valid HTML ID and make sure it is unique. + $variables['block_html_id'] = drupal_html_id('block-' . $variables['block']->module . '-' . $variables['block']->delta); + $attributes['id'] = $variables['block_html_id']; + } + else { + // We are providing an explicit ID for the block, so use that. + $variables['block_html_id'] = $attributes['id']; + } + + // Inject the classes into the attributes array and the template system. + $attributes['class'][] = drupal_html_class('block-' . $variables['block']->module); + $variables['classes_array'] = $attributes['class']; + $variables['attributes_array'] = $attributes; } /** diff --git a/modules/block/block.tpl.php b/modules/block/block.tpl.php index c1025c3..f6fa949 100644 --- a/modules/block/block.tpl.php +++ b/modules/block/block.tpl.php @@ -10,13 +10,12 @@ * - $block->module: Module that generated the block. * - $block->delta: An ID for the block, unique within each module. * - $block->region: The block region embedding the current block. - * - $classes: String of classes that can be used to style contextually through - * CSS. It can be manipulated through the variable $classes_array from - * preprocess functions. The default values can be one or more of the following: - * - block: The current template type, i.e., "theming hook". - * - block-[module]: The module generating the block. For example, the user module - * is responsible for handling the default user navigation block. In that case - * the class would be "block-user". + * - $block->attributes: An array of attributes to apply to the block itself. + * This generally holds a number of values: + * - id: The ID name for the block (block-[module]-[delta]). + * - class: An array of classes to apply to the block (block-[module]). + * - $attributes: String of attributes that should be applied to the block. This + * is generated from the $block->attributes variable. * - $title_prefix (array): An array containing additional output populated by * modules, intended to be displayed in front of the main title tag that * appears in the template. @@ -25,8 +24,9 @@ * the template. * * Helper variables: - * - $classes_array: Array of html class attribute values. It is flattened - * into a string within the variable $classes. + * - $attributes_array: An array of attributes to associate with the block. + * - $classes_array: An array of class to style the block. + * - $classes: A string representing all the classes to apply to the block. * - $block_zebra: Outputs 'odd' and 'even' dependent on each block region. * - $zebra: Same output as $block_zebra but independent of any block region. * - $block_id: Counter dependent on each block region. @@ -41,7 +41,7 @@ * @see template_process() */ ?> -
> +> subject): ?> diff --git a/modules/book/book.module b/modules/book/book.module index 779c907..aab8a89 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -292,6 +292,7 @@ function book_block_view($delta = '') { $data = array_shift($tree); $block['subject'] = theme('book_title_link', array('link' => $data['link'])); $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : ''; + $block['attributes']['role'] = 'complementary'; } } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index f9af40a..5252c88 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -454,7 +454,7 @@ function comment_block_view($delta = '') { if (user_access('access comments')) { $block['subject'] = t('Recent comments'); $block['content'] = theme('comment_block'); - + $block['attributes']['role'] = 'navigation'; return $block; } } diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 65c5489..92cf87b 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -674,6 +674,7 @@ function forum_block_view($delta = '') { // Cache based on the altered query. Enables us to cache with node access enabled. $block['content'] = drupal_render_cache_by_query($query, 'forum_block_view'); $block['content']['#access'] = user_access('access content'); + $block['attributes']['role'] = 'navigation'; return $block; } diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 6bb697d..6441c74 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -992,6 +992,7 @@ function locale_block_view($type) { $variables = array('links' => $links->links, 'attributes' => array('class' => array($class))); $block['content'] = theme('links__locale_block', $variables); $block['subject'] = t('Languages'); + $block['attributes']['role'] = 'complementary'; return $block; } } diff --git a/modules/menu/menu.module b/modules/menu/menu.module index cd42256..6c0eef8 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -472,6 +472,7 @@ function menu_block_view($delta = '') { if (!empty($data['content'])) { $data['content']['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($delta)); } + $data['attributes']['role'] = 'navigation'; return $data; } diff --git a/modules/node/node.module b/modules/node/node.module index 0c3cfb7..cef3c31 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -2129,11 +2129,13 @@ function node_block_view($delta = '') { '#url' => 'rss.xml', '#title' => t('Syndicate'), ); + $block['attributes']['role'] = 'complementary'; break; case 'recent': if (user_access('access content')) { $block['subject'] = t('Recent content'); + $block['attributes']['role'] = 'navigation'; if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) { $block['content'] = array( '#theme' => 'node_recent_block', diff --git a/modules/poll/poll.module b/modules/poll/poll.module index ec5452e..ced7e4a 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -160,6 +160,7 @@ function poll_block_view($delta = '') { $poll = poll_block_latest_poll_view($poll); $block['subject'] = t('Poll'); $block['content'] = $poll->content; + $block['attributes']['role'] = 'complementary'; return $block; } } diff --git a/modules/search/search.module b/modules/search/search.module index 5844f6e..3465368 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -149,6 +149,7 @@ function search_block_view($delta = '') { if (user_access('search content')) { $block['subject'] = t('Search'); $block['content'] = drupal_get_form('search_block_form'); + $block['attributes']['role'] = 'search'; return $block; } } diff --git a/modules/shortcut/shortcut.module b/modules/shortcut/shortcut.module index f8ddcc2..b714148 100644 --- a/modules/shortcut/shortcut.module +++ b/modules/shortcut/shortcut.module @@ -202,6 +202,7 @@ function shortcut_block_view($delta = '') { $shortcut_set = shortcut_current_displayed_set(); $data['subject'] = t('@shortcut_set shortcuts', array('@shortcut_set' => $shortcut_set->title)); $data['content'] = shortcut_renderable_links($shortcut_set); + $data['attributes']['role'] = 'navigation'; return $data; } } diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 0ba9d7f..327ed25 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -365,6 +365,7 @@ function statistics_block_view($delta = '') { if (count($content)) { $block['content'] = $content; $block['subject'] = t('Popular content'); + $block['attributes']['role'] = 'navigation'; return $block; } } diff --git a/modules/system/system.module b/modules/system/system.module index 0ef688e..f8af53f 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -2049,14 +2049,17 @@ function system_block_view($delta = '') { case 'main': $block['subject'] = NULL; $block['content'] = drupal_set_page_content(); + $block['attributes']['role'] = 'main'; return $block; case 'powered-by': $block['subject'] = NULL; $block['content'] = theme('system_powered_by'); + $block['attributes']['role'] = 'complementary'; return $block; case 'help': $block['subject'] = NULL; $block['content'] = menu_get_active_help(); + $block['attributes']['role'] = 'complementary'; return $block; default: // All system menu blocks. @@ -2064,6 +2067,9 @@ function system_block_view($delta = '') { if (isset($system_menus[$delta])) { $block['subject'] = t($system_menus[$delta]); $block['content'] = menu_tree($delta); + $block['attributes']['role'] = 'navigation'; + // System menu blocks should get the same class as menu module blocks. + $block['attributes']['class'][] = 'block-menu'; return $block; } break; @@ -2071,16 +2077,6 @@ function system_block_view($delta = '') { } /** - * Implements hook_preprocess_block(). - */ -function system_preprocess_block(&$variables) { - // System menu blocks should get the same class as menu module blocks. - if ($variables['block']->module == 'system' && in_array($variables['block']->delta, array_keys(menu_list_system_menus()))) { - $variables['classes_array'][] = 'block-menu'; - } -} - -/** * Provide a single block on the administration overview page. * * @param $item diff --git a/modules/user/user.module b/modules/user/user.module index 14e1459..cb8937b 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1341,6 +1341,7 @@ function user_block_view($delta = '') { $block['subject'] = t('User login'); $block['content'] = drupal_get_form('user_login_block'); + $block['attributes']['role'] = 'form'; } return $block; @@ -1352,6 +1353,7 @@ function user_block_view($delta = '') { $block['subject'] = t('Who\'s new'); $block['content'] = $output; + $block['attributes']['role'] = 'complementary'; } return $block; @@ -1375,6 +1377,7 @@ function user_block_view($delta = '') { $block['subject'] = t('Who\'s online'); $block['content'] = $output; + $block['attributes']['role'] = 'complementary'; } return $block; }