Projet

Général

Profil

Paste
Télécharger (1,79 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / templates / book / book-navigation.vars.php @ 4eeb3b46

1
<?php
2
/**
3
 * @file
4
 * Stub file for "book_navigation" theme hook [pre]process functions.
5
 */
6

    
7
/**
8
 * Pre-processes variables for the "book_navigation" theme hook.
9
 *
10
 * See template for list of available variables.
11
 *
12
 * @see book-navigation.tpl.php
13
 *
14
 * @ingroup theme_preprocess
15
 */
16
function bootstrap_preprocess_book_navigation(&$variables) {
17
  $variables['tree'] = _bootstrap_book_children($variables['book_link']);
18
}
19

    
20
/**
21
 * Formats the menu links for the child pages of the current page.
22
 *
23
 * @param array $book_link
24
 *   A fully loaded menu link that is part of the book hierarchy.
25
 *
26
 * @return string
27
 *   HTML for the links to the child pages of the current page.
28
 */
29
function _bootstrap_book_children($book_link) {
30
  // Rebuild entire menu tree for the book.
31
  $tree = menu_build_tree($book_link['menu_name']);
32
  $tree = menu_tree_output($tree);
33

    
34
  // Fix the theme hook suggestions.
35
  _bootstrap_book_fix_theme_hooks($book_link['nid'], $tree);
36

    
37
  // Return the rendered output.
38
  return drupal_render($tree);
39
}
40

    
41
/**
42
 * Helper function to fix theme hooks in book TOC menus.
43
 *
44
 * @param int $bid
45
 *   The book identification number.
46
 * @param array $element
47
 *   The element to iterate over, passed by reference.
48
 * @param int $level
49
 *   Used internally to determine the current level of the menu.
50
 */
51
function _bootstrap_book_fix_theme_hooks($bid, array &$element, $level = 0) {
52
  $hook = $level === 0 ? $bid : 'sub_menu__' . $bid;
53
  $element['#theme_wrappers'] = array('menu_tree__book_toc__' . $hook);
54
  foreach (element_children($element) as $child) {
55
    $element[$child]['#theme'] = 'menu_link__book_toc__' . $hook;
56
    // Iterate through all child menu items as well.
57
    if (!empty($element[$child]['#below'])) {
58
      _bootstrap_book_fix_theme_hooks($bid, $element[$child]['#below'], ($level + 1));
59
    }
60
  }
61
}