Projet

Général

Profil

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

root / drupal7 / sites / all / themes / bootstrap / templates / menu / menu-link.func.php @ 1f623f01

1
<?php
2
/**
3
 * @file
4
 * Stub file for bootstrap_menu_link() and suggestion(s).
5
 */
6

    
7
/**
8
 * 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
 */
21
function bootstrap_menu_link(array $variables) {
22
  $element = $variables['element'];
23
  $sub_menu = '';
24

    
25
  $title = $element['#title'];
26
  $href = $element['#href'];
27
  $options = !empty($element['#localized_options']) ? $element['#localized_options'] : array();
28
  $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array();
29

    
30
  if ($element['#below']) {
31
    // Prevent dropdown functions from being added to management menu so it
32
    // does not affect the navbar module.
33
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
34
      $sub_menu = drupal_render($element['#below']);
35
    }
36
    elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
37
      // Add our own wrapper.
38
      unset($element['#below']['#theme_wrappers']);
39
      $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
40

    
41
      // Generate as standard dropdown.
42
      $title .= ' <span class="caret"></span>';
43
      $attributes['class'][] = 'dropdown';
44

    
45
      $options['html'] = TRUE;
46

    
47
      // Set dropdown trigger element to # to prevent inadvertant page loading
48
      // when a submenu link is clicked.
49
      $options['attributes']['data-target'] = '#';
50
      $options['attributes']['class'][] = 'dropdown-toggle';
51
      $options['attributes']['data-toggle'] = 'dropdown';
52
    }
53
  }
54

    
55
  // Filter the title if the "html" is set, otherwise l() will automatically
56
  // sanitize using check_plain(), so no need to call that here.
57
  if (!empty($options['html'])) {
58
    $title = _bootstrap_filter_xss($title);
59
  }
60

    
61
  return '<li' . drupal_attributes($attributes) . '>' . l($title, $href, $options) . $sub_menu . "</li>\n";
62
}
63

    
64
/**
65
 * Overrides theme_menu_link() for book module.
66
 */
67
function bootstrap_menu_link__book_toc(array $variables) {
68
  $element = $variables['element'];
69
  $sub_menu = drupal_render($element['#below']);
70

    
71
  $title = $element['#title'];
72
  $href = $element['#href'];
73
  $options = !empty($element['#localized_options']) ? $element['#localized_options'] : array();
74
  $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array();
75
  $attributes['role'] = 'presentation';
76

    
77
  // Header.
78
  $link = TRUE;
79
  if ($title && $href === FALSE) {
80
    $attributes['class'][] = 'dropdown-header';
81
    $link = FALSE;
82
  }
83
  // Divider.
84
  elseif ($title === FALSE && $href === FALSE) {
85
    $attributes['class'][] = 'divider';
86
    $link = FALSE;
87
  }
88
  // Active.
89
  elseif (($href == $_GET['q'] || ($href == '<front>' && drupal_is_front_page())) && (empty($options['language']))) {
90
    $attributes['class'][] = 'active';
91
  }
92

    
93
  // Filter the title if the "html" is set, otherwise l() will automatically
94
  // sanitize using check_plain(), so no need to call that here.
95
  if (!empty($options['html'])) {
96
    $title = _bootstrap_filter_xss($title);
97
  }
98

    
99
  // Convert to a link.
100
  if ($link) {
101
    $title = l($title, $href, $options);
102
  }
103

    
104
  return '<li' . drupal_attributes($attributes) . '>' . $title . $sub_menu . "</li>\n";
105
}