diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 290d0e6001ec4bf95b44a4ac86d9112ac840550d..e338fd15906e1927f6e69e31e06a156794b9d8b9 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2135,6 +2135,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, ); @@ -2146,6 +2147,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 ceffa1ff5d0536112d82fe838f7606080004df1d..8c40c497e666d683efa2cd715dc34f81fecb7639 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 5f11fbae7c1e0a5f25c4babfef97527a66fc5a9d..ad4b4d0adb7aa07fc9b6ad3423f646e4e0843d3a 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -361,15 +361,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. * @@ -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 b36beff95e5f0715c3ba3d7651bf89a2abff33c6..604dbe6c5fc797de80216d864d4f18bce94fc056 100644 --- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php @@ -136,6 +136,9 @@ public function build() { $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) { return array( 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 b84b59308123f58758d18f842dc426cea58c60e6..61609826f9a2e768ec18059a5322a74e0864f9d0 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 %} -