/
template.php
376 lines (339 loc) · 12.3 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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
/**
* @file
* This file is empty by default because the base theme chain (Alpha & Omega) provides
* all the basic functionality. However, in case you wish to customize the output that Drupal
* generates through Alpha & Omega this file is a good place to do so.
*
* Alpha comes with a neat solution for keeping this file as clean as possible while the code
* for your subtheme grows. Please read the README.txt in the /preprocess and /process subfolders
* for more information on this topic.
*/
/**
* Implements hook_theme().
*/
function suitcase_interim_theme($existing, $type, $theme, $path) {
return array(
'smartmenu_link' => array(
'render element' => 'element',
),
'smartmenu_tree' => array(
'render element' => 'tree',
),
);
}
function suitcase_interim_facetapi_deactivate_widget($variables) {
return '<span class="facetapi-x">×</span>';
}
/*
* Implements hook_form_FORMID_alter()
*/
function suitcase_interim_form_search_block_form_alter(&$form, &$form_state, $form_id) {
$form['actions']['submit']['#value'] = ' ';
$form['#attributes']['role'] = 'search';
}
/* Menu Theme Functions */
/*
* Implements theme_smartmenu_tree().
*
* Modified version of theme_menu_tree
*
* -------------------------------------------------------------------------
*
* Returns HTML for a wrapper for a menu sub-tree.
*
* @param $variables
* An associative array containing:
* - tree: An HTML string containing the tree's items.
*
* @see template_preprocess_menu_tree()
* @ingroup themeable
*
* -------------------------------------------------------------------------
*
* Modifications:
*
* - Doesn't have a template_preprocess function like theme_menu_tree.
* Instead, the tree variable provided should be the full tree from
* suitcase_interim_smartmenu_tree_output
*
* - Applies attributes (if supplied) to the menu sub-tree
*
* - Does not apply the 'menu' class by default
*
*/
function suitcase_interim_smartmenu_tree($variables) {
$tree = $variables['tree'];
if (!empty($tree['#attributes'])) {
return '<ul' . drupal_attributes($tree['#attributes']) . '>' . $tree['#children'] . '</ul>';
} else {
return '<ul>' . $tree['#children'] . '</ul>';
}
}
/*
* Implements theme_smartmenu_link().
*
* Modified version of theme_menu_link
*
* -------------------------------------------------------------------------
*
* Returns HTML for a menu link and submenu.
*
* @param $variables
* An associative array containing:
* - element: Structured array data for a menu link.
*
* @ingroup themeable
*
* -------------------------------------------------------------------------
*
* Modifications:
*
* - Only adds the submenu to the output if the link it set to 'Always Show Expanded'
*
*/
function suitcase_interim_smartmenu_link(array $variables) {
$element = $variables['element'];
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
if ($element['#original_link']['expanded']) {
$output .= $sub_menu;
}
}
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . "</li>\n";
}
/*
*
* Modified version of menu_tree_output
*
* -------------------------------------------------------------------------
*
* Returns an output structure for rendering a menu tree.
*
* The menu item's LI element is given one of the following classes:
* - expanded: The menu item is showing its submenu.
* - collapsed: The menu item has a submenu which is not shown.
* - leaf: The menu item has no submenu.
*
* @param $tree
* A data structure representing the tree as returned from menu_tree_data.
*
* @return
* A structured array to be rendered by drupal_render().
*
* -------------------------------------------------------------------------
*
* Modifications:
*
* - Uses theme_smartmenu_tree as a theme_wrapper rather than theme_menu_tree
* This is important because template_preprocess_menu_tree removes depth
* information from from the tree and working around this requires altering the
* theme registry. See https://www.drupal.org/node/767404
*
* - Adds the active classes for absolute url matches (including query string).
* This does not handle the case, which might be considered a core bug, where
* multiple menu items that link to the same page and differ only in query strings
* will both highlight upon visiting either of them.
*
* - Accepts an array of attributes to apply to the generated list
*
*/
function suitcase_interim_smartmenu_tree_output($tree, $attributes = NULL) {
$build = array();
$items = array();
// Pull out just the menu links we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $data) {
if ($data['link']['access'] && !$data['link']['hidden']) {
$items[] = $data;
}
}
$router_item = menu_get_item();
$num_items = count($items);
foreach ($items as $i => $data) {
$class = array();
if ($i == 0) {
$class[] = 'first';
}
if ($i == $num_items - 1) {
$class[] = 'last';
}
// Set a class for the <li>-tag. Since $data['below'] may contain local
// tasks, only set 'expanded' class if the link also has children within
// the current menu.
if ($data['link']['has_children'] && $data['below']) {
$class[] = 'expanded';
}
elseif ($data['link']['has_children']) {
$class[] = 'collapsed';
}
else {
$class[] = 'leaf';
}
// Set a class if the link is in the active trail.
if ($data['link']['in_active_trail']) {
$class[] = 'active-trail';
$data['link']['localized_options']['attributes']['class'][] = 'active-trail';
}
// Normally, l() compares the href of every link with $_GET['q'] and sets
// the active class accordingly. But local tasks do not appear in menu
// trees, so if the current path is a local task, and this link is its
// tab root, then we have to set the class manually.
if ($data['link']['href'] == $router_item['tab_root_href'] && $data['link']['href'] != $_GET['q']) {
$data['link']['localized_options']['attributes']['class'][] = 'active';
}
if (($data['link']['href'] == $_GET['q'] || $data['link']['href'] == ($GLOBALS['base_root'] . request_uri())) || ($data['link']['href'] == '<front>' && drupal_is_front_page())) {
$class[] = 'active';
$class[] = 'active-trail';
$data['link']['localized_options']['attributes']['class'][] = 'active';
$data['link']['localized_options']['attributes']['class'][] = 'active-trail';
}
// Allow menu-specific theme overrides.
$element['#theme'] = 'smartmenu_link';
$element['#attributes']['class'] = $class;
$element['#title'] = $data['link']['title'];
$element['#href'] = $data['link']['href'];
$element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();
$element['#below'] = $data['below'] ? suitcase_interim_smartmenu_tree_output($data['below']) : $data['below'];
$element['#original_link'] = $data['link'];
// Index using the link's unique mlid.
$build[$data['link']['mlid']] = $element;
}
if ($build) {
// Make sure drupal_render() does not re-order the links.
$build['#sorted'] = TRUE;
$build['#attributes'] = $attributes;
$build['#tree'] = $build;
$build['#theme_wrappers'][] = 'smartmenu_tree';
}
return $build;
}
/**
* Implements theme_date_display_range
*
* This is an exact copy of theme_date_display_range from the Date module v7.x-2.10-rc1
* Earlier versions of the Date module use div wrappers rather spans, causing HTML validation errors
* The Date module has not had a stable release for 7.x since 2015-09-07, over a year ago, so we provide this for now
*/
function suitcase_interim_date_display_range($variables) {
$date1 = $variables['date1'];
$date2 = $variables['date2'];
$timezone = $variables['timezone'];
$attributes_start = $variables['attributes_start'];
$attributes_end = $variables['attributes_end'];
$show_remaining_days = $variables['show_remaining_days'];
$start_date = '<span class="date-display-start"' . drupal_attributes($attributes_start) . '>' . $date1 . '</span>';
$end_date = '<span class="date-display-end"' . drupal_attributes($attributes_end) . '>' . $date2 . $timezone . '</span>';
// If microdata attributes for the start date property have been passed in,
// add the microdata in meta tags.
if (!empty($variables['add_microdata'])) {
$start_date .= '<meta' . drupal_attributes($variables['microdata']['value']['#attributes']) . '/>';
$end_date .= '<meta' . drupal_attributes($variables['microdata']['value2']['#attributes']) . '/>';
}
// Wrap the result with the attributes.
$output = '<span class="date-display-range">' . t('!start-date to !end-date', array(
'!start-date' => $start_date,
'!end-date' => $end_date,
)) . '</span>';
// Add remaining message and return.
return $output . $show_remaining_days;
}
/**
* Implements theme_facetapi_link_active().
*
* Modified version of theme_facetapi_link_active
*
* -------------------------------------------------------------------------
*
* Returns HTML for an active facet item.
*
* @param $variables
* An associative array containing the keys 'text', 'path', and 'options'. See
* the l() function for information about these variables.
*
* @see l()
*
* @ingroup themeable
*
* -------------------------------------------------------------------------
*
* Modifications:
*
* - Includes the tag name in the link text instead of appending after the link
*
*/
function suitcase_interim_facetapi_link_active($variables) {
// Sanitizes the link text if necessary.
$sanitize = empty($variables['options']['html']);
$link_text = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
// Theme function variables fro accessible markup.
// @see http://drupal.org/node/1316580
$accessible_vars = array(
'text' => $variables['text'],
'active' => TRUE,
);
// Builds link, passes through t() which gives us the ability to change the
// position of the widget on a per-language basis.
$replacements = array(
'!facetapi_deactivate_widget' => theme('facetapi_deactivate_widget', $variables),
'!facetapi_accessible_markup' => theme('facetapi_accessible_markup', $accessible_vars),
);
$variables['text'] = t('!facetapi_deactivate_widget !facetapi_accessible_markup', $replacements) . $link_text;
$variables['options']['html'] = TRUE;
return theme_link($variables);
}
/*
* Implements theme_menu_link()
*
* Modified version of theme_menu_link
*
* -------------------------------------------------------------------------
*
* Returns HTML for a menu link and submenu.
*
* @param $variables
* An associative array containing:
* - element: Structured array data for a menu link.
*
* @ingroup themeable
*
* -------------------------------------------------------------------------
*
* Modifications:
*
* - Prepends a font awesome icon for known social media websites to the link text
*
*/
function suitcase_interim_menu_link__menu_social($variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$font_awesome_icons = array(
'facebook' => 'fa-facebook-official',
'twitter' => 'fa-twitter-square',
'youtube' => 'fa-youtube-square',
'instagram' => 'fa-instagram',
'pinterest' => 'fa-pinterest-square',
'github' => 'fa-github-square',
'rss' => 'fa-rss-square',
'snapchat' => 'fa-snapchat-square',
'flickr' => 'fa-flickr',
'linkedin' => 'fa-linkedin-square'
);
$font_awesome_icon = '';
foreach ($font_awesome_icons as $pattern => $icon) {
if (strpos($element['#href'], $pattern) !== FALSE) {
$font_awesome_icon = $icon;
break;
}
}
if (!empty($font_awesome_icon)) {
$element['#title'] = '<span class="fa ' . $font_awesome_icon . '" aria-hidden="true"></span><span class="social-title"> ' . $element['#title'] . '</span>';
$element['#localized_options']['html'] = TRUE;
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}