Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Stub file for bootstrap_menu_link() and suggestion(s).
6
 */
7

    
8
/**
9
 * Returns HTML for a menu link and submenu.
10
 *
11
 * @param array $variables
12
 *   An associative array containing:
13
 *   - element: Structured array data for a menu link.
14
 *
15
 * @return string
16
 *   The constructed HTML.
17
 *
18
 * @see theme_menu_link()
19
 *
20
 * @ingroup theme_functions
21
 */
22
function bootstrap_menu_link(array $variables) {
23
  $element = $variables['element'];
24
  $sub_menu = '';
25

    
26
  $options = !empty($element['#localized_options']) ? $element['#localized_options'] : array();
27

    
28
  // Check plain title if "html" is not set, otherwise, filter for XSS attacks.
29
  $title = empty($options['html']) ? check_plain($element['#title']) : filter_xss_admin($element['#title']);
30

    
31
  // Ensure "html" is now enabled so l() doesn't double encode. This is now
32
  // safe to do since both check_plain() and filter_xss_admin() encode HTML
33
  // entities. See: https://www.drupal.org/node/2854978
34
  $options['html'] = TRUE;
35

    
36
  $href = $element['#href'];
37
  $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array();
38

    
39
  if ($element['#below']) {
40
    // Prevent dropdown functions from being added to management menu so it
41
    // does not affect the navbar module.
42
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
43
      $sub_menu = drupal_render($element['#below']);
44
    }
45
    elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
46
      // Add our own wrapper.
47
      unset($element['#below']['#theme_wrappers']);
48
      $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
49

    
50
      // Generate as standard dropdown.
51
      $title .= ' <span class="caret"></span>';
52
      $attributes['class'][] = 'dropdown';
53

    
54
      // Set dropdown trigger element to # to prevent inadvertant page loading
55
      // when a submenu link is clicked.
56
      $options['attributes']['data-target'] = '#';
57
      $options['attributes']['class'][] = 'dropdown-toggle';
58
      $options['attributes']['data-toggle'] = 'dropdown';
59
    }
60
  }
61

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

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

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

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

    
94
  // Convert to a link.
95
  if ($link) {
96
    $title = l($title, $href, $options);
97
  }
98
  // Otherwise, filter the title if "html" is not set, otherwise l() will
99
  // automatically sanitize using check_plain(), so no need to call that here.
100
  elseif (empty($options['html'])) {
101
    $title = filter_xss_admin($title);
102
  }
103

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