Projet

Général

Profil

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

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

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
  if ($element['#below']) {
26
    // Prevent dropdown functions from being added to management menu so it
27
    // does not affect the navbar module.
28
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
29
      $sub_menu = drupal_render($element['#below']);
30
    }
31
    elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
32
      // Add our own wrapper.
33
      unset($element['#below']['#theme_wrappers']);
34
      $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
35
      // Generate as standard dropdown.
36
      $element['#title'] .= ' <span class="caret"></span>';
37
      $element['#attributes']['class'][] = 'dropdown';
38
      $element['#localized_options']['html'] = TRUE;
39

    
40
      // Set dropdown trigger element to # to prevent inadvertant page loading
41
      // when a submenu link is clicked.
42
      $element['#localized_options']['attributes']['data-target'] = '#';
43
      $element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
44
      $element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
45
    }
46
  }
47
  // On primary navigation menu, class 'active' is not set on active menu item.
48
  // @see https://drupal.org/node/1896674
49
  if (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
50
    $element['#attributes']['class'][] = 'active';
51
  }
52
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
53
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
54
}
55

    
56
/**
57
 * Overrides theme_menu_link() for book module.
58
 */
59
function bootstrap_menu_link__book_toc(array $variables) {
60
  $element = $variables['element'];
61
  $sub_menu = drupal_render($element['#below']);
62
  $element['#attributes']['role'] = 'presentation';
63
  $link = TRUE;
64
  if ($element['#title'] && $element['#href'] === FALSE) {
65
    $element['#attributes']['class'][] = 'dropdown-header';
66
    $link = FALSE;
67
  }
68
  elseif ($element['#title'] === FALSE && $element['#href'] === FALSE) {
69
    $element['#attributes']['class'][] = 'divider';
70
    $link = FALSE;
71
  }
72
  elseif (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
73
    $element['#attributes']['class'][] = 'active';
74
  }
75
  if ($link) {
76
    $element['#title'] = l($element['#title'], $element['#href'], $element['#localized_options']);
77
  }
78
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $element['#title'] . $sub_menu . "</li>\n";
79
}