Projet

Général

Profil

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

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

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
      $options['attributes']['class'][] = 'dropdown-toggle';
54
      $options['attributes']['data-toggle'] = 'dropdown';
55
    }
56
  }
57

    
58
  return '<li' . drupal_attributes($attributes) . '>' . l($title, $href, $options) . $sub_menu . "</li>\n";
59
}
60

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

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

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

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

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