-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
executable file
·311 lines (273 loc) · 9.21 KB
/
template.php
File metadata and controls
executable file
·311 lines (273 loc) · 9.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
include_once(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/twitter_bootstrap.inc');
include_once(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/modules/theme.inc');
include_once(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/modules/pager.inc');
include_once(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/modules/form.inc');
include_once(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/modules/admin.inc');
include_once(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/modules/menu.inc');
// Load module include files
$modules = module_list();
foreach ($modules as $module) {
if (is_file(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/modules/' . str_replace('_', '-', $module) . '.inc')) {
include_once(drupal_get_path('theme', 'twitter_bootstrap') . '/includes/modules/' . str_replace('_', '-', $module) . '.inc');
}
}
/**
* hook_theme()
*/
function twitter_bootstrap_theme() {
return array(
'twitter_bootstrap_links' => array(
'variables' => array('links' => array(), 'attributes' => array(), 'heading' => NULL),
),
'twitter_bootstrap_btn_dropdown' => array(
'variables' => array('links' => array(), 'attributes' => array(), 'type' => NULL),
),
'twitter_bootstrap_btn_dropdown_menu_wrapper' => array(
'render element' => 'tree',
),
);
}
function twitter_bootstrap_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
$breadcrumbs = '<ul class="breadcrumb">';
$count = count($breadcrumb) - 1;
foreach($breadcrumb as $key => $value) {
if($count != $key) {
$breadcrumbs .= '<li>'.$value.'<span class="divider">/</span></li>';
}else{
$breadcrumbs .= '<li>'.$value.'</li>';
}
}
$breadcrumbs .= '</ul>';
return $breadcrumbs;
}
}
/**
* Preprocess variables for node.tpl.php
*
* @see node.tpl.php
*/
function twitter_bootstrap_preprocess_node(&$variables) {
if ($variables['teaser']) {
$variables['classes_array'][] = 'row-fluid';
}
}
/**
* Preprocess variables for block.tpl.php
*
* @see block.tpl.php
*/
function twitter_bootstrap_preprocess_block(&$variables, $hook) {
//$variables['classes_array'][] = 'row';
// Use a bare template for the page's main content.
if ($variables['block_html_id'] == 'block-system-main') {
$variables['theme_hook_suggestions'][] = 'block__no_wrapper';
}
$variables['title_attributes_array']['class'][] = 'block-title';
}
/**
* Override or insert variables into the block templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function twitter_bootstrap_process_block(&$variables, $hook) {
// Drupal 7 should use a $title variable instead of $block->subject.
$variables['title'] = $variables['block']->subject;
}
/**
* Preprocess variables for page.tpl.php
*
* @see page.tpl.php
*/
function twitter_bootstrap_preprocess_page(&$variables) {
// Add information about the number of sidebars.
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$variables['columns'] = 3;
}
elseif (!empty($variables['page']['sidebar_first'])) {
$variables['columns'] = 2;
}
elseif (!empty($variables['page']['sidebar_second'])) {
$variables['columns'] = 2;
}
else {
$variables['columns'] = 1;
}
// Our custom search because its cool :)
$variables['search'] = FALSE;
if (theme_get_setting('toggle_search') && module_exists('search')) {
$variables['search'] = drupal_get_form('_twitter_bootstrap_search_form');
}
// Primary nav
$variables['primary_nav'] = FALSE;
if($variables['main_menu']) {
// Build links
$tree = menu_tree_page_data(variable_get('menu_main_links_source', 'main-menu'));
$variables['main_menu'] = twitter_bootstrap_menu_navigation_links($tree);
// Build list
$variables['primary_nav'] = theme('twitter_bootstrap_links', array(
'links' => $variables['main_menu'],
'attributes' => array(
'id' => 'main-menu',
'class' => array('nav'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
}
// Secondary nav
$variables['secondary_nav'] = FALSE;
if($variables['secondary_menu']) {
$secondary_menu = menu_load(variable_get('menu_secondary_links_source', 'user-menu'));
// Build links
$tree = menu_tree_page_data($secondary_menu['menu_name']);
$variables['secondary_menu'] = twitter_bootstrap_menu_navigation_links($tree);
// Build list
$variables['secondary_nav'] = theme('twitter_bootstrap_btn_dropdown', array(
'links' => $variables['secondary_menu'],
'label' => $secondary_menu['title'],
'type' => 'success',
'attributes' => array(
'id' => 'user-menu',
'class' => array('pull-right'),
),
'heading' => array(
'text' => t('Secondary menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
}
// Replace tabs with dropw down version
$variables['tabs']['#primary'] = _twitter_bootstrap_local_tasks($variables['tabs']['#primary']);
}
function _twitter_bootstrap_search_form($form, &$form_state) {
// Get custom search form for now
$form = search_form($form, $form_state);
// Cleanup
$form['#attributes']['class'][] = 'navbar-search';
$form['#attributes']['class'][] = 'pull-left';
$form['basic']['keys']['#title'] = '';
$form['basic']['keys']['#attributes']['class'][] = 'search-query';
$form['basic']['keys']['#attributes']['class'][] = 'span2';
$form['basic']['keys']['#attributes']['placeholder'] = t('Search');
unset($form['basic']['submit']);
unset($form['basic']['#type']);
unset($form['basic']['#attributes']);
$form += $form['basic'];
unset($form['basic']);
return $form;
}
/**
* Preprocess variables for region.tpl.php
*
* @see region.tpl.php
*/
function twitter_bootstrap_preprocess_region(&$variables, $hook) {
if ($variables['region'] == 'content') {
$variables['theme_hook_suggestions'][] = 'region__no_wrapper';
}
// Me likes
if ($variables['region'] == "sidebar_first") {
$variables['classes_array'][] = 'well';
}
}
/**
* Returns the correct span class for a region
*/
function _twitter_bootstrap_content_span($columns = 1) {
$class = FALSE;
switch($columns) {
case 1:
$class = 'span12';
break;
case 2:
$class = 'span9';
break;
case 3:
$class = 'span6';
break;
}
return $class;
}
/**
* Preprocess variables for panels-pane.tpl.php
*
* @see panels-pane.tpl.php
*/
function twitter_bootstrap_preprocess_panels_pane(&$variables) {
switch ($variables['pane']->type) {
case 'page_content':
$variables['hide_wrappers'] = TRUE;
break;
case 'page_slogan':
$variables['theme_hook_suggestion'] = 'panels_pane__page_slogan';
break;
case 'page_site_name':
$variables['theme_hook_suggestion'] = 'panels_pane__page_site_name';
break;
case 'page_logo':
$variables['classes_array'][] = 'brand';
break;
case 'block':
// Search form in sticky bar has specific look.
// @todo make universal way for forms in this region.
if ($variables['pane']->subtype == 'search-form' && $variables['pane']->panel == 'sticky_bar_navigation_left') {
$variables['classes_array'][] = 'navbar-search';
unset($variables['content']['actions']);
$variables['content']['search_block_form']['#attributes']['class'][] = 'span2';
$variables['content']['search_block_form']['#attributes']['class'][] = 'search-query';
$variables['content']['search_block_form']['#attributes']['placeholder'] = $variables['content']['search_block_form']['#title'];
}
break;
}
if ($variables['pane']->panel == 'sticky_bar_navigation_left') {
$variables['classes_array'][] = 'pull-left';
}
elseif ($variables['pane']->panel == 'sticky_bar_navigation_right') {
$variables['classes_array'][] = 'pull-right';
}
}
/**
* Implements theme_panels_default_style_render_region().
*/
function twitter_bootstrap_panels_default_style_render_region(&$variables) {
$output = implode('', $variables['panes']);
$no_wrapper_regions = array('content', 'sticky_bar_navigation_left', 'sticky_bar_navigation_right', 'sticky_bar_logo');
if (!in_array($variables['region_id'], $no_wrapper_regions) && !empty($output)) {
$classes = array(
'region',
'region-' . str_replace('_', '-', $variables['region_id']),
);
if($variables['region_id'] == "sidebar_first") {
$classes[] = 'well';
}
$output = '<div class="' . implode(' ', $classes) . '">' . $output . '</div>';
}
return $output;
}
/**
* Return bootstrap default button's types.
*/
function twitter_bootstrap_get_button_types() {
return variable_get(
'twitter_bootstrap_button_types',
array(
'default' => t('Default'),
'primary' => t('Primary'),
'danger' => t('Danger'),
'warning' => t('Warning'),
'success' => t('Success'),
'info' => t('Info'),
'inverse' => t('Inverse'),
)
);
}