Projet

Général

Profil

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

root / drupal7 / sites / all / themes / bootstrap / templates / book / book-navigation.vars.php @ 6d8023f2

1 caf16a48 Assos Assos
<?php
2 eefc2ac0 Assos Assos
3 caf16a48 Assos Assos
/**
4
 * @file
5
 * Stub file for "book_navigation" theme hook [pre]process functions.
6
 */
7
8
/**
9
 * Pre-processes variables for the "book_navigation" theme hook.
10
 *
11
 * See template for list of available variables.
12
 *
13 eefc2ac0 Assos Assos
 * @param array $variables
14
 *   An associative array of variables, passed by reference.
15
 *
16 caf16a48 Assos Assos
 * @see book-navigation.tpl.php
17
 *
18
 * @ingroup theme_preprocess
19
 */
20 eefc2ac0 Assos Assos
function bootstrap_preprocess_book_navigation(array &$variables) {
21 caf16a48 Assos Assos
  $variables['tree'] = _bootstrap_book_children($variables['book_link']);
22
}
23
24
/**
25
 * Formats the menu links for the child pages of the current page.
26
 *
27
 * @param array $book_link
28
 *   A fully loaded menu link that is part of the book hierarchy.
29
 *
30
 * @return string
31
 *   HTML for the links to the child pages of the current page.
32
 */
33 eefc2ac0 Assos Assos
function _bootstrap_book_children(array $book_link) {
34 caf16a48 Assos Assos
  // Rebuild entire menu tree for the book.
35
  $tree = menu_build_tree($book_link['menu_name']);
36
  $tree = menu_tree_output($tree);
37
38
  // Fix the theme hook suggestions.
39
  _bootstrap_book_fix_theme_hooks($book_link['nid'], $tree);
40
41
  // Return the rendered output.
42
  return drupal_render($tree);
43
}
44
45
/**
46
 * Helper function to fix theme hooks in book TOC menus.
47
 *
48
 * @param int $bid
49
 *   The book identification number.
50
 * @param array $element
51
 *   The element to iterate over, passed by reference.
52
 * @param int $level
53
 *   Used internally to determine the current level of the menu.
54
 */
55
function _bootstrap_book_fix_theme_hooks($bid, array &$element, $level = 0) {
56
  $hook = $level === 0 ? $bid : 'sub_menu__' . $bid;
57
  $element['#theme_wrappers'] = array('menu_tree__book_toc__' . $hook);
58
  foreach (element_children($element) as $child) {
59
    $element[$child]['#theme'] = 'menu_link__book_toc__' . $hook;
60
    // Iterate through all child menu items as well.
61
    if (!empty($element[$child]['#below'])) {
62
      _bootstrap_book_fix_theme_hooks($bid, $element[$child]['#below'], ($level + 1));
63
    }
64
  }
65
}