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.
Related Issues
#2052473: Add aria-label or aria-describedby attributes to all <nav> elements
Comment | File | Size | Author |
---|---|---|---|
book-module-all-books-block-template-vars-fix.patch | 1.1 KB | jessebeach | |
Comments
Comment #1
cosmicdreams CreditAttribution: cosmicdreams commentedReviewed 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.
Comment #2
Xanobook-module-all-books-block-template-vars-fix.patch queued for re-testing.
Comment #3
Xanobook-module-all-books-block-template-vars-fix.patch queued for re-testing.
Comment #4
webchickWow, nice sleuthing!
Committed and pushed to 8.x. Thanks!