diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 2b06429..6e3f6e9 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2136,6 +2136,7 @@ function template_preprocess_page(&$variables) { '#heading' => array( 'text' => t('Main menu'), 'class' => array('visually-hidden'), + 'attributes' => array('id' => 'links__system_main_menu'), ), '#set_active_class' => TRUE, ); @@ -2147,6 +2148,7 @@ function template_preprocess_page(&$variables) { '#heading' => array( 'text' => t('Secondary menu'), 'class' => array('visually-hidden'), + 'attributes' => array('id' => 'links__system_secondary_menu'), ), '#set_active_class' => TRUE, ); diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 37b93bd..b129be5 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -382,6 +382,13 @@ function template_preprocess_block(&$variables) { if ($id = $variables['elements']['#block']->id()) { $variables['attributes']['id'] = drupal_html_id('block-' . $id); } + + // Proactively add aria-describedby if possible to improve accessibility. + if (isset($variables['elements']['#block']->subject) && isset($variables['attributes']['role'])) { + $variables['title_attributes']['id'] = drupal_html_id($variables['elements']['#block']->subject); + $variables['attributes']['aria-describedby'] = $variables['title_attributes']['id']; + } + } /** diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 9cc4835..71290bd 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -362,15 +362,6 @@ function book_form_node_delete_confirm_alter(&$form, $form_state) { } /** - * Implements hook_preprocess_HOOK() for block templates. - */ -function book_preprocess_block(&$variables) { - if ($variables['configuration']['provider'] == 'book') { - $variables['attributes']['role'] = 'navigation'; - } -} - -/** * Prepares variables for book listing block templates. * * Default template: book-all-books-block.html.twig. @@ -389,7 +380,11 @@ function template_preprocess_book_all_books_block(&$variables) { $elements = $variables['book_menus']; $variables['book_menus'] = array(); foreach (Element::children($elements) as $index) { - $variables['book_menus'][$index] = $elements[$index]; + $variables['book_menus'][] = array( + 'id' => $index, + 'menu' => $elements[$index], + 'title' => $elements[$index]['#book_title'], + ); } } diff --git a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php index b36beff..ca59e66 100644 --- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php @@ -125,6 +125,9 @@ public function build() { // needs to be retrieved. $data = $this->bookManager->bookTreeAllData($node->book['bid'], $node->book); $book_menus[$book_id] = $this->bookManager->bookTreeOutput($data); + $book_menus[$book_id] += array( + '#book_title' => $node->book['title'], + ); } else { // Since we know we will only display a link to the top node, there @@ -135,6 +138,9 @@ public function build() { $book['access'] = $book_node->access('view'); $pseudo_tree[0]['link'] = $book; $book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree); + $book_menus[$book_id] += array( + '#book_title' => $book['title'], + ); } } if ($book_menus) { diff --git a/core/modules/book/templates/book-all-books-block.html.twig b/core/modules/book/templates/book-all-books-block.html.twig index b84b593..6160982 100644 --- a/core/modules/book/templates/book-all-books-block.html.twig +++ b/core/modules/book/templates/book-all-books-block.html.twig @@ -8,7 +8,8 @@ * * Available variables: * - book_menus: Book outlines. - * - book_id: The parent book ID. + * - id: The parent book ID. + * - title: The parent book title. * - menu: The top-level book links. * * @see template_preprocess_book_all_books_block() @@ -16,8 +17,8 @@ * @ingroup themeable */ #} -{% for book_id, menu in book_menus %} -