root / drupal7 / sites / all / themes / bootstrap / templates / menu / menu-link.func.php @ 0939d55c
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 |
// Check plain title if "html" is not set, otherwise, filter for XSS attacks.
|
28 |
$title = empty($options['html']) ? check_plain($element['#title']) : filter_xss_admin($element['#title']); |
29 |
|
30 |
// Ensure "html" is now enabled so l() doesn't double encode. This is now
|
31 |
// safe to do since both check_plain() and filter_xss_admin() encode HTML
|
32 |
// entities. See: https://www.drupal.org/node/2854978
|
33 |
$options['html'] = TRUE; |
34 |
|
35 |
$href = $element['#href']; |
36 |
$attributes = !empty($element['#attributes']) ? $element['#attributes'] : array(); |
37 |
|
38 |
if ($element['#below']) { |
39 |
// Prevent dropdown functions from being added to management menu so it
|
40 |
// does not affect the navbar module.
|
41 |
if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) { |
42 |
$sub_menu = drupal_render($element['#below']); |
43 |
} |
44 |
elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) { |
45 |
// Add our own wrapper.
|
46 |
unset($element['#below']['#theme_wrappers']); |
47 |
$sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>'; |
48 |
|
49 |
// Generate as standard dropdown.
|
50 |
$title .= ' <span class="caret"></span>'; |
51 |
$attributes['class'][] = 'dropdown'; |
52 |
|
53 |
// Set dropdown trigger element to # to prevent inadvertant page loading
|
54 |
// when a submenu link is clicked.
|
55 |
$options['attributes']['data-target'] = '#'; |
56 |
$options['attributes']['class'][] = 'dropdown-toggle'; |
57 |
$options['attributes']['data-toggle'] = 'dropdown'; |
58 |
} |
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 |
// Convert to a link.
|
94 |
if ($link) { |
95 |
$title = l($title, $href, $options); |
96 |
} |
97 |
// Otherwise, filter the title if "html" is not set, otherwise l() will automatically
|
98 |
// sanitize using check_plain(), so no need to call that here.
|
99 |
elseif (empty($options['html'])) { |
100 |
$title = filter_xss_admin($title); |
101 |
} |
102 |
|
103 |
return '<li' . drupal_attributes($attributes) . '>' . $title . $sub_menu . "</li>\n"; |
104 |
} |