root / drupal7 / sites / all / themes / bootstrap / templates / menu / menu-link.func.php @ 7547bb19
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 |
$options = !empty($element['#localized_options']) ? $element['#localized_options'] : array(); |
26 |
|
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 |
$attributes = !empty($element['#attributes']) ? $element['#attributes'] : array(); |
33 |
|
34 |
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 |
|
45 |
// Generate as standard dropdown.
|
46 |
$title .= ' <span class="caret"></span>'; |
47 |
$attributes['class'][] = 'dropdown'; |
48 |
|
49 |
$options['html'] = TRUE; |
50 |
|
51 |
// Set dropdown trigger element to # to prevent inadvertant page loading
|
52 |
// when a submenu link is clicked.
|
53 |
$options['attributes']['data-target'] = '#'; |
54 |
$options['attributes']['class'][] = 'dropdown-toggle'; |
55 |
$options['attributes']['data-toggle'] = 'dropdown'; |
56 |
} |
57 |
} |
58 |
|
59 |
return '<li' . drupal_attributes($attributes) . '>' . l($title, $href, $options) . $sub_menu . "</li>\n"; |
60 |
} |
61 |
|
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 |
|
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 |
$link = TRUE; |
77 |
if ($title && $href === FALSE) { |
78 |
$attributes['class'][] = 'dropdown-header'; |
79 |
$link = FALSE; |
80 |
} |
81 |
// Divider.
|
82 |
elseif ($title === FALSE && $href === FALSE) { |
83 |
$attributes['class'][] = 'divider'; |
84 |
$link = FALSE; |
85 |
} |
86 |
// 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 |
if ($link) { |
93 |
$title = l($title, $href, $options); |
94 |
} |
95 |
// 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 |
|
101 |
return '<li' . drupal_attributes($attributes) . '>' . $title . $sub_menu . "</li>\n"; |
102 |
} |