Problem/Motivation

The data passed to the theme_book_all_books_block theme function contain a spurious parent array around the book menu arrays, thus we end up with this markup:

<div id="book-block-menu-0" class="book-block-menu">
  <ul class="menu clearfix">
    <li class="first last collapsed"><a href="/node/1">just some stuff</a></li>
  </ul>
  <ul class="menu clearfix">
    <li class="first last collapsed"><a href="/node/3">sdfserefsf</a></li>
  </ul>
</div>

When we should have this markup:

<div id="book-block-menu-1" class="book-block-menu">
  <ul class="menu clearfix">
    <li class="first last collapsed"><a href="/node/1">just some stuff</a></li>
  </ul>
</div>
<div id="book-block-menu-3" class="book-block-menu">
  <ul class="menu clearfix">
    <li class="first last collapsed"><a href="/node/3">sdfserefsf</a></li>
  </ul>
</div>

Note that the individual menus are wrapped by one div in the wrong example, not individual divs with the correct book menu ids which in this case should be 1 and 3, not 0.

I encountered this issue while doing some accessibility work.

Proposed resolution

This is happening because the variable data passed to the theme function is constructed like this:

if ($book_menus) {
  return array(
    '#theme' => 'book_all_books_block',
    $book_menus,
  );
}

which introduces a secret little [0] indexed array around the $book_menus array.

We can get around this by taking the union of the arrays like so:

if ($book_menus) {
  return array(
    '#theme' => 'book_all_books_block',
  ) + $book_menus;
}

Thus maintaining the individual book menu indices as siblings to the #theme index.

Remaining tasks

Review the patch.

User interface changes

We'll get the right markup.

API changes

None.

#2052473: Add aria-label or aria-describedby attributes to all <nav> elements

Comments

cosmicdreams’s picture

Status: Active » Reviewed & tested by the community

Reviewed and tested on simplytest.me

1. turned on book
2. created a page and made it a book
3. Created another page and assigned it to the same book
4. Added Book Navigation block to sidebar.
5. Confirmed everything looked fine.

xano’s picture

xano’s picture

webchick’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Wow, nice sleuthing!

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.