If you have a theme that defines its own menu class like:
/**
* Returns HTML for a wrapper for a menu sub-tree.
*/
function mytheme_menu_tree($variables) {
return '<ul class="foo-menu">' . $variables['tree'] . '</ul>';
}
the book menu theming becomes a real mess as you need to add a function for every single book menu, but you do not know when a user creates a new book id.
function mytheme_menu_tree__book_toc_4($variables) {
return '<ul class="menu">' . $variables['tree'] . '</ul>';
}
function mytheme_menu_tree__book_toc_5($variables) {
return '<ul class="menu">' . $variables['tree'] . '</ul>';
}
This shows once more how inflexible menu theming is.
I think D7 book module should add this:
/**
* Implements hook_theme().
*/
function book_theme($existing, $type, $theme, $path) {
// Book module assigns an incrementing bid to every new book and
// menu_tree_output() does not add any useful wildcard suggestion.
$books = db_query('SELECT DISTINCT bid FROM {book}');
foreach ($books as $book) {
// Override theming for every single book id.
$items['menu_tree__book_toc_' . $book->bid] = array(
'render element' => 'tree',
'function' => 'theme_book_tree',
'preprocess functions' => array('template_preprocess_book_tree'),
);
}
return $items;
}
/**
* Returns HTML for a wrapper for a book menu sub-tree.
*
* @param $variables
* An associative array containing:
* - tree: An HTML string containing the tree's items.
*
* @see template_preprocess_book_menu_tree()
* @ingroup themeable
*/
function theme_book_tree($variables) {
return '<ul class="menu">' . $variables['tree'] . '</ul>';
}
/**
* Implements template_preprocess_HOOK() for theme_book_menu_tree().
*/
function template_preprocess_book_tree(&$variables) {
$variables['tree'] = $variables['tree']['#children'];
}
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | Issue-2461575-by-hass-Book-menu-clash-with-menutree-D7.patch | 2.02 KB | hass |
Comments
Comment #1
hass commentedComment #2
hass commentedNavbar module has already added the same workaround.
Comment #3
hass commentedComment #4
hass commentedReplaced one navbar note.
Comment #5
hass commentedComment #6
hass commentedComment #7
hass commentedLooks like this has already been fixed in D8 long time ago.
Comment #8
hass commentedRenamed functions to D8 names
Comment #9
hass commentedComment #10
hass commentedTypos fixed