-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.php
258 lines (235 loc) · 8.04 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
/**
* @file
* Template overrides as well as (pre-)process and alter hooks for the
* Excellent Schools Detroit theme.
*/
/**
* Implements hook_omega_theme_libraries_info().
*/
function esd_omega_theme_libraries_info($theme) {
$path = drupal_get_path('theme', 'esd');
$libraries['selectnav'] = array(
'name' => t('Selectnav'),
'description' => t("selectnav.js library"),
'package' => t('esd'),
'files' => array(
'js' => array(
$path . '/js/selectnav/selectnav.min.js' => array(
'group' => JS_THEME,
'weight' => -100,
'every_page' => TRUE,
),
),
),
);
$libraries['responsive'] = array(
'name' => t('Responsive Libs'),
'description' => t('Responsive libraries and plugins'),
'package' => t('esd'),
'files' => array(
'js' => array(
$path . '/js/jquery.resizeend.js' => array(
'group' => JS_THEME,
'weight' => -101,
'every_page' => TRUE,
),
$path . '/js/jquery.matchmedia.js' => array(
'group' => JS_THEME,
'weight' => -100,
'every_page' => TRUE,
),
),
),
);
$libraries['esd_frontend'] = array(
'name' => t('Excellent Schools Detroit Frontend'),
'description' => t('esd frontend magic'),
'package' => t('esd'),
'files' => array(
'js' => array(
$path . '/js/esd_frontend.js' => array(
'group' => JS_THEME,
'weight' => 100,
'every_page' => TRUE,
),
),
),
);
$libraries['imgsizer'] = array(
'name' => t('ImgSizer'),
'description' => t('Image sizer plugin'),
'package' => t('esd'),
'files' => array(
'js' => array(
$path . '/js/imgsizer.js' => array(
'group' => JS_THEME,
'weight' => 80,
'every_page' => TRUE,
),
),
),
);
$libraries['superfish'] = array(
'name' => t('Superfish'),
'description' => t('Superfish dropdown menus'),
'package' => t('esd'),
'files' => array(
'js' => array(
$path . '/js/superfish.js' => array(
'group' => JS_THEME,
'weight' => 90,
'every_page' => TRUE,
),
),
),
);
return $libraries;
}
/**
* Implements template_preprocess_page
*/
function esd_preprocess_page(&$vars) {
drupal_add_js('jQuery.extend(Drupal.settings, { "pathToTheme": "/' . path_to_theme() . '/" });', 'inline');
if (in_array('node', $vars, TRUE) && is_object($vars['node'])) {
if ($vars['node']->type == 'blog_entry') {
// Set Page title to Blog on blog nodes.
$vars['title'] = l('Blog', 'blog');
}
if ($vars['node']->type == 'media_hit') {
// Set Page title to Media Archive on media hit nodes.
$vars['title'] = l('Media Archive', 'media');
}
}
}
/**
* Implements template_preprocess_node
*/
function esd_preprocess_node(&$vars) {
// Re-order the links.
if (isset($vars['content']['links'])) {
$vars['content']['links'] = array_reverse($vars['content']['links']);
}
// Add wrapper & "from" to media outlet field
if (isset($vars['content']['field_media_outlet'])) {
$vars['content']['field_media_outlet']['#prefix'] = '<div class="media-hit-outlet-wrapper"><span class="italic">from</span>';
$vars['content']['field_media_outlet']['#suffix'] = '</div>';
}
if (isset($vars['content']['links']['translation'])) {
// Remove the language link on nodes.
unset($vars['content']['links']['translation']);
}
// On school profiles, load School term
if (isset($vars['field_school']['und']['0']['tid'])) {
$school_term = taxonomy_term_load($vars['field_school']['und']['0']['tid']);
$school_info = taxonomy_term_view($school_term);
$school_aside = taxonomy_term_view($school_term, 'aside');
if (isset($school_term->field_bcode['und'][0]['value'])) {
$vars['school_score_link'] = l('View 2013 Scores', 'schoolscores/2013/' . $school_term->field_bcode['und'][0]['value']);
$vars['school_score_link'] .= l('View 2014 Scores', 'schoolscores/2014/' . $school_term->field_bcode['und'][0]['value']);
}
$vars['school_info'] = render($school_info);
if (array_key_exists('field_files', $school_aside) || array_key_exists('field_links', $school_aside)) {
$vars['school_aside'] = render($school_aside, 'aside');
}
}
}
/**
* Implements template_preprocess_search_result().
*/
function esd_preprocess_search_result(&$vars) {
if ($vars['result']['language'] == 'es') {
$vars['lang_indicator'] = '<span class="es" title="' . t('Spanish') . '">ES</span>';
} else {
$vars['lang_indicator'] = '<span class="en" title="' . t('English') . '">EN</span>';
}
// Adds lang_path variable to search result.
if ($vars['result']['language'] != 'und') {
$vars['lang_path'] = '/' . $vars['result']['language'] . '/' . drupal_get_path_alias('node/' . $vars['result']['node']->nid, $vars['result']['language']);
} else {
$vars['lang_path'] = $vars['result']['link'];
}
}
/**
* Implements theme_file_icon().
*/
function esd_file_icon($variables) {
$file = $variables['file'];
if ($file->filemime == 'application/pdf') {
// Override PDF icon
$icon_directory = drupal_get_path('theme', 'esd') . '/images/file-icons';
} else {
$icon_directory = $variables['icon_directory'];
}
$mime = check_plain($file->filemime);
$icon_url = file_icon_url($file, $icon_directory);
return '<img alt="" class="file-icon" src="' . $icon_url . '" title="' . $mime . '" />';
}
function esd_field_multiple_value_form($variables) {
$element = $variables['element'];
$output = '';
if ($element['#cardinality'] > 1 || $element['#cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
$table_id = drupal_html_id($element['#field_name'] . '_values');
$order_class = $element['#field_name'] . '-delta-order';
$required = !empty($element['#required']) ? theme('form_required_marker', $variables) : '';
$header = array();
$rows = array();
// Sort items according to '_weight' (needed when the form comes back after
// preview or failed validation)
$items = array();
foreach (element_children($element) as $key) {
if ($key === 'add_more') {
$add_more_button = &$element[$key];
}
else {
$items[] = &$element[$key];
}
}
usort($items, '_field_sort_items_value_helper');
// Add the items as table rows.
foreach ($items as $key => $item) {
$item['_weight']['#attributes']['class'] = array($order_class);
$delta_element = drupal_render($item['_weight']);
$cells = array(
array(
'data' => '',
'class' => array('field-multiple-drag'),
),
drupal_render($item),
array(
'data' => $delta_element,
'class' => array('delta-order'),
),
);
$rows[] = array(
'data' => $cells,
'class' => array('draggable'),
);
}
$output = '<div class="form-item">';
$output .= '<label>' . t('!title !required', array('!title' => $element['#title'], '!required' => $required)) . "</label>";
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => $table_id, 'class' => array('field-multiple-table'))));
$output .= $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '';
$output .= '<div class="clearfix">' . drupal_render($add_more_button) . '</div>';
$output .= '</div>';
drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class);
}
else {
foreach (element_children($element) as $key) {
$output .= drupal_render($element[$key]);
}
}
return $output;
}
/**
* Implements theme_preprocess_user_profile().
* via https://drupal.org/node/1161236#comment-6163514
*/
function esd_preprocess_user_profile(&$vars) {
$account = $vars['elements']['#account'];
foreach (element_children($vars['elements']) as $key) {
$vars['user_profile'][$key] = $vars['elements'][$key];
}
$vars['user_profile']['mail'] = $account->mail;
field_attach_preprocess('user', $account, $vars['elements'], $vars);
}