Projet

Général

Profil

Paste
Télécharger (3,33 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / templates / menu / menu-link.func.php @ 7547bb19

1 87dbc3bf Benjamin Luce
<?php
2
/**
3
 * @file
4 caf16a48 Assos Assos
 * Stub file for bootstrap_menu_link() and suggestion(s).
5 87dbc3bf Benjamin Luce
 */
6
7
/**
8 caf16a48 Assos Assos
 * Returns HTML for a menu link and submenu.
9
 *
10
 * @param array $variables
11
 *   An associative array containing:
12
 *   - element: Structured array data for a menu link.
13
 *
14
 * @return string
15
 *   The constructed HTML.
16
 *
17
 * @see theme_menu_link()
18
 *
19
 * @ingroup theme_functions
20 87dbc3bf Benjamin Luce
 */
21
function bootstrap_menu_link(array $variables) {
22
  $element = $variables['element'];
23
  $sub_menu = '';
24
25 1f623f01 Assos Assos
  $options = !empty($element['#localized_options']) ? $element['#localized_options'] : array();
26 7547bb19 Assos Assos
27
  // Filter the title if the "html" is not set, otherwise l() will automatically
28
  // sanitize using check_plain(), so no need to call that here.
29
  $title = empty($options['html']) ? filter_xss_admin($element['#title']) : $element['#title'];
30
31
  $href = $element['#href'];
32 1f623f01 Assos Assos
  $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array();
33
34 87dbc3bf Benjamin Luce
  if ($element['#below']) {
35
    // Prevent dropdown functions from being added to management menu so it
36
    // does not affect the navbar module.
37
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
38
      $sub_menu = drupal_render($element['#below']);
39
    }
40
    elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
41
      // Add our own wrapper.
42
      unset($element['#below']['#theme_wrappers']);
43
      $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
44 1f623f01 Assos Assos
45 87dbc3bf Benjamin Luce
      // Generate as standard dropdown.
46 1f623f01 Assos Assos
      $title .= ' <span class="caret"></span>';
47
      $attributes['class'][] = 'dropdown';
48
49
      $options['html'] = TRUE;
50 87dbc3bf Benjamin Luce
51
      // Set dropdown trigger element to # to prevent inadvertant page loading
52
      // when a submenu link is clicked.
53 1f623f01 Assos Assos
      $options['attributes']['data-target'] = '#';
54
      $options['attributes']['class'][] = 'dropdown-toggle';
55
      $options['attributes']['data-toggle'] = 'dropdown';
56 87dbc3bf Benjamin Luce
    }
57
  }
58 1f623f01 Assos Assos
59
  return '<li' . drupal_attributes($attributes) . '>' . l($title, $href, $options) . $sub_menu . "</li>\n";
60 87dbc3bf Benjamin Luce
}
61 caf16a48 Assos Assos
62
/**
63
 * Overrides theme_menu_link() for book module.
64
 */
65
function bootstrap_menu_link__book_toc(array $variables) {
66
  $element = $variables['element'];
67
  $sub_menu = drupal_render($element['#below']);
68 1f623f01 Assos Assos
69
  $title = $element['#title'];
70
  $href = $element['#href'];
71
  $options = !empty($element['#localized_options']) ? $element['#localized_options'] : array();
72
  $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array();
73
  $attributes['role'] = 'presentation';
74
75
  // Header.
76 caf16a48 Assos Assos
  $link = TRUE;
77 1f623f01 Assos Assos
  if ($title && $href === FALSE) {
78
    $attributes['class'][] = 'dropdown-header';
79 caf16a48 Assos Assos
    $link = FALSE;
80
  }
81 1f623f01 Assos Assos
  // Divider.
82
  elseif ($title === FALSE && $href === FALSE) {
83
    $attributes['class'][] = 'divider';
84 caf16a48 Assos Assos
    $link = FALSE;
85
  }
86 1f623f01 Assos Assos
  // Active.
87
  elseif (($href == $_GET['q'] || ($href == '<front>' && drupal_is_front_page())) && (empty($options['language']))) {
88
    $attributes['class'][] = 'active';
89
  }
90
91
  // Convert to a link.
92 caf16a48 Assos Assos
  if ($link) {
93 1f623f01 Assos Assos
    $title = l($title, $href, $options);
94 caf16a48 Assos Assos
  }
95 7547bb19 Assos Assos
  // Otherwise, filter the title if "html" is not set, otherwise l() will automatically
96
  // sanitize using check_plain(), so no need to call that here.
97
  elseif (empty($options['html'])) {
98
    $title = filter_xss_admin($title);
99
  }
100 1f623f01 Assos Assos
101
  return '<li' . drupal_attributes($attributes) . '>' . $title . $sub_menu . "</li>\n";
102 caf16a48 Assos Assos
}