1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
function bootstrap_preprocess_bootstrap_dropdown(&$variables) {
|
17
|
$element = &$variables['element'];
|
18
|
|
19
|
|
20
|
$element += array(
|
21
|
'#wrapper_attributes' => NULL,
|
22
|
'#attributes' => NULL,
|
23
|
'#alignment' => NULL,
|
24
|
'#toggle' => NULL,
|
25
|
'#items' => NULL,
|
26
|
);
|
27
|
|
28
|
|
29
|
$element['#wrapper_attributes']['class'][] = 'dropdown';
|
30
|
if ($element['#alignment'] === 'up' || (is_array($element['#alignment']) && in_array('up', $element['#alignment']))) {
|
31
|
$element['#wrapper_attributes']['class'][] = 'dropup';
|
32
|
}
|
33
|
|
34
|
if (isset($element['#toggle'])) {
|
35
|
if (is_string($element['#toggle'])) {
|
36
|
$element['#toggle'] = array(
|
37
|
'#theme' => 'link__bootstrap_dropdown__toggle',
|
38
|
'#text' => _bootstrap_filter_xss($element['#toggle']),
|
39
|
'#path' => '#',
|
40
|
'#options' => array(
|
41
|
'attributes' => array(),
|
42
|
'html' => TRUE,
|
43
|
'external' => TRUE,
|
44
|
),
|
45
|
);
|
46
|
}
|
47
|
if (isset($element['#toggle']['#options']['attributes'])) {
|
48
|
$element['#toggle']['#options']['attributes']['class'][] = 'dropdown-toggle';
|
49
|
$element['#toggle']['#options']['attributes']['data-toggle'] = 'dropdown';
|
50
|
}
|
51
|
else {
|
52
|
$element['#toggle']['#attributes']['class'][] = 'dropdown-toggle';
|
53
|
$element['#toggle']['#attributes']['data-toggle'] = 'dropdown';
|
54
|
}
|
55
|
}
|
56
|
|
57
|
|
58
|
$element['#attributes']['role'] = 'menu';
|
59
|
$element['#attributes']['class'][] = 'dropdown-menu';
|
60
|
if ($element['#alignment'] === 'right' || (is_array($element['#alignment']) && in_array('right', $element['#alignment']))) {
|
61
|
$element['#attributes']['class'][] = 'dropdown-menu-right';
|
62
|
}
|
63
|
}
|
64
|
|
65
|
|
66
|
|
67
|
|
68
|
|
69
|
|
70
|
|
71
|
|
72
|
|
73
|
|
74
|
function bootstrap_process_bootstrap_dropdown(&$variables) {
|
75
|
$element = &$variables['element'];
|
76
|
|
77
|
$items = array();
|
78
|
foreach ($element['#items'] as $data) {
|
79
|
$item_classes = array();
|
80
|
|
81
|
|
82
|
if (empty($data)) {
|
83
|
$data = '';
|
84
|
$item_classes[] = 'divider';
|
85
|
}
|
86
|
|
87
|
elseif (is_array($data) && (!empty($data['header']) || !empty($data['#header']))) {
|
88
|
$item_classes[] = 'dropdown-header';
|
89
|
}
|
90
|
|
91
|
elseif (is_array($data) && (!empty($data['disabled']) || !empty($data['#disabled']))) {
|
92
|
$item_classes[] = 'disabled';
|
93
|
}
|
94
|
|
95
|
elseif (is_array($data) && (!empty($data['active']) || !empty($data['#active']))) {
|
96
|
$item_classes[] = 'active';
|
97
|
}
|
98
|
|
99
|
|
100
|
$item = array(
|
101
|
'data' => render($data),
|
102
|
'role' => 'presentation',
|
103
|
);
|
104
|
if (!empty($item_classes)) {
|
105
|
$item['class'] = $item_classes;
|
106
|
}
|
107
|
$items[] = $item;
|
108
|
}
|
109
|
|
110
|
|
111
|
$variables['dropdown'] = array(
|
112
|
'#theme_wrappers' => array('container'),
|
113
|
'#attributes' => $element['#wrapper_attributes'],
|
114
|
'toggle' => $element['#toggle'],
|
115
|
'items' => array(
|
116
|
'#theme' => 'item_list__bootstrap_dropdown',
|
117
|
'#items' => $items,
|
118
|
'#attributes' => $element['#attributes'],
|
119
|
),
|
120
|
);
|
121
|
}
|