This repository has been archived by the owner on May 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.php
234 lines (198 loc) · 7.58 KB
/
template.php
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
<?php
/**
* @file
* Template.php for bang theme.
*/
/**
* Implements template_preprocess_html().
*/
function bang_preprocess_html(&$vars) {
// TypeKit.
drupal_add_js('//use.typekit.net/qqr6kuv.js', array('type' => 'external'));
$data = 'try{Typekit.load();}catch (e){}';
drupal_add_js($data, array('type' => 'inline'));
}
/**
* Implements theme_menu_link().
*
* Add specific markup for top-bar menu exposed as menu_block_4.
*/
function bang_menu_link__menu_tabs_menu($vars) {
// Run classes array through our custom stripper.
$vars['element']['#attributes']['class'] = ddbasic_remove_default_link_classes($vars['element']['#attributes']['class']);
// Check if the class array is empty.
if (empty($vars['element']['#attributes']['class'])) {
unset($vars['element']['#attributes']['class']);
}
$element = $vars['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
// Add default class to a tag.
$element['#localized_options']['attributes']['class'] = array(
'menu-item',
);
// Make sure text string is treated as html by l function.
$element['#localized_options']['html'] = TRUE;
$element['#localized_options']['attributes']['class'][] = 'js-topbar-link';
$title_prefix = '';
// Add some icons to our top-bar menu. We use system paths to check against.
switch ($element['#href']) {
case 'search':
$title_prefix = '<i class="icon-search"></i>';
$element['#localized_options']['attributes']['class'][] = 'topbar-link-search';
$element['#attributes']['class'][] = 'topbar-link-search';
$element['#title'] = '';
break;
case 'node':
// Special placeholder for mobile user menu. Fall through to next case.
$element['#localized_options']['attributes']['class'][] = 'default-override';
case 'user':
// If a user is logged in we change the menu item title.
if (user_is_logged_in()) {
$element['#title'] = t('My Account');
$element['#attributes']['class'][] = 'topbar-link-user-account';
$element['#localized_options']['attributes']['class'][] = 'topbar-link-user-account';
}
else {
$element['#attributes']['class'][] = 'topbar-link-user';
$element['#localized_options']['attributes']['class'][] = 'topbar-link-user';
}
break;
case 'user/logout':
$element['#localized_options']['attributes']['class'][] = 'topbar-link-signout';
$element['#attributes']['class'][] = 'topbar-link-signout';
// For some unknown issue translation fails for this title.
$element['#title'] = t($element['#title']);
break;
default:
$element['#localized_options']['attributes']['class'][] = 'topbar-link-menu';
$element['#attributes']['class'][] = 'topbar-link-menu';
break;
}
$output = l($title_prefix . '<span>' . $element['#title'] . '</span>', $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
/**
* Implements hook_preprocess_field().
*/
function bang_preprocess_field(&$vars) {
$element = $vars['element'];
if ($element['#field_name'] == 'field_ding_eresource_access') {
// Remove the clearfix class from ding_eresource_access field.
// It messes with our floating of the logo.
$clearfix_index = array_search('clearfix', $vars['classes_array']);
if ($clearfix_index !== FALSE) {
unset($vars['classes_array'][$clearfix_index]);
}
}
}
/**
* Implements hook_preprocess_form_element().
*/
function bang_preprocess_form_element(&$vars) {
$element = &$vars['element'];
if (empty($element['#wrapper_attributes'])) {
$element['#wrapper_attributes'] = array();
}
// Add class to form item if it has a label.
if (!empty($element['#title'])) {
$element['#wrapper_attributes']['class'][] = 'form-item-has-label';
}
}
/**
* Implements hook_js_alter().
*/
function bang_js_alter(&$js) {
unset($js['profiles/ding2/themes/ddbasic/scripts/ddbasic.topbar.menu.min.js']);
}
/**
* Implements theme_form_element().
*
* This is basically copy/pasted from theme_form_element with the addition of
* basing wrapper attributes on the #attributes value. This allows preprocess
* functions to add classes to form elements.
*/
function bang_form_element($variables) {
$element = &$variables['element'];
// This function is invoked as theme wrapper, but the rendered form element
// may not necessarily have been processed by form_builder().
$element += array(
'#title_display' => 'before',
);
// This is where changes have been introduced.
// Base attributes on the #attributes value for the element and remember to
// initialize the classes array.
$attributes = $element['#wrapper_attributes'];
if (!isset($attributes['class'])) {
$attributes['class'] = array();
}
// Add element #id for #type 'item'.
if (isset($element['#markup']) && !empty($element['#id'])) {
$attributes['id'] = $element['#id'];
}
// Add element's #type and #name as class to aid with JS/CSS selectors.
// Add the base form-item class to the array.
$attributes['class'][] = 'form-item';
if (!empty($element['#type'])) {
$attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
}
if (!empty($element['#name'])) {
$attributes['class'][] = 'form-item-' . strtr($element['#name'],
array(
' ' => '-',
'_' => '-',
'[' => '-',
']' => '',
));
}
// Add a class for disabled elements to facilitate cross-browser styling.
if (!empty($element['#attributes']['disabled'])) {
$attributes['class'][] = 'form-disabled';
}
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
// If #title is not set, we don't display any label or required marker.
if (!isset($element['#title'])) {
$element['#title_display'] = 'none';
}
$prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
$suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
switch ($element['#title_display']) {
case 'before':
case 'invisible':
$output .= ' ' . theme('form_element_label', $variables);
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
case 'after':
$output .= ' ' . $prefix . $element['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
break;
case 'none':
case 'attribute':
// Output no label and no required marker, only the children.
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
}
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
$output .= "</div>\n";
return $output;
}
/**
* Implements hook_preprocess_node().
*
* Override or insert variables into the node templates.
*/
function bang_preprocess_node(&$variables, $hook) {
// Create single event locations to make them appear with an icon each.
if (is_array($variables['ddbasic_event_location'])) {
foreach (element_children($variables['ddbasic_event_location']) as $index) {
$variables['ddbasic_event_locations'][] = $variables['ddbasic_event_location'][$index];
}
}
elseif (isset($variables['ddbasic_event_location'])) {
$variables['ddbasic_event_locations'][] = $variables['ddbasic_event_location'];
}
}