forked from odensecentralbibliotek/ddbasic
-
Notifications
You must be signed in to change notification settings - Fork 4
/
template.php
1012 lines (873 loc) · 31.4 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Preprocess and Process Functions.
*/
// Includes frequently used theme functions that gets theme info, css files etc.
include_once drupal_get_path('theme', 'ddbasic') . '/inc/functions.inc';
/**
* Implements hook_preprocess_html().
*/
function ddbasic_preprocess_html(&$vars) {
global $language;
// Setup iOS logo if it's set.
$vars['ios_logo'] = theme_get_setting('iosicon_upload');
// Set variable for the base path.
$vars['base_path'] = base_path();
// Clean up the lang attributes.
$vars['html_attributes'] = 'lang="' . $language->language . '" dir="' . $language->dir . '"';
// Load ddbasic plugins.
ddbasic_load_plugins();
// Add conditional CSS for IE8.
drupal_add_css(path_to_theme() . '/css/ddbasic.ie8.css', array(
'group' => CSS_THEME,
'browsers' => array(
'IE' => 'lte IE 8',
'!IE' => FALSE,
),
'weight' => 999,
'preprocess' => FALSE,
));
// Add conditional CSS for IE9.
drupal_add_css(path_to_theme() . '/css/ddbasic.ie9.css', array(
'group' => CSS_THEME,
'browsers' => array(
'IE' => 'lte IE 9',
'!IE' => FALSE,
),
'weight' => 999,
'preprocess' => FALSE,
));
}
/**
* Implements hook_process_html().
*
* Process variables for html.tpl.php
*/
function ddbasic_process_html(&$vars) {
// Classes for body element. Allows advanced theming based on context
// (home page, node of certain type, etc.)
if (!$vars['is_front']) {
// Add unique class for each page.
$path = drupal_get_path_alias($_GET['q']);
// Add unique class for each website section.
$section = explode('/', $path);
$section = array_shift($section);
$arg = explode('/', $_GET['q']);
if ($arg[0] == 'node' && isset($arg[1])) {
if ($arg[1] == 'add') {
$section = 'node-add';
}
elseif (isset($arg[2]) && is_numeric($arg[1]) && ($arg[2] == 'edit' || $arg[2] == 'delete')) {
$section = 'node-' . $arg[2];
}
}
$vars['classes_array'][] = drupal_html_class('section-' . $section);
}
// Store the menu item since it has some useful information.
$vars['menu_item'] = menu_get_item();
if ($vars['menu_item']) {
switch ($vars['menu_item']['page_callback']) {
case 'views_page':
// Is this a Views page?
$vars['classes_array'][] = 'page-views';
break;
case 'page_manager_page_execute':
case 'page_manager_node_view':
case 'page_manager_contact_site':
// Is this a Panels page?
$vars['classes_array'][] = 'page-panels';
break;
}
}
// Color module.
// Hook into color.module.
if (module_exists('color')) {
_color_html_alter($vars);
}
}
/**
* Implements hook_form_alter().
*/
function ddbasic_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'search_block_form':
$form['search_block_form']['#attributes']['placeholder'] = t('Search the library');
$form['search_block_form']['#field_prefix'] = '<i class="icon-search"></i>';
$form['search_block_form']['#title'] = t('Search the library database and the website');
// Remove element-invisible
unset($form['search_block_form']['#title_display']);
break;
case 'user_login_block':
$form['name']['#title'] = t('Loan or social security number');
$form['name']['#field_prefix'] = '<i class="icon-user"></i>';
$form['name']['#attributes']['placeholder'] = t('The number is 10 digits');
$form['name']['#type'] = 'password';
$form['pass']['#title'] = t('Pincode');
$form['pass']['#field_prefix'] = '<i class="icon-lock"></i>';
$form['pass']['#attributes']['placeholder'] = t('Pincode is 4 digits');
unset($form['links']);
// Temporary hack to get rid of open id links.
unset($form['openid_links']);
unset($form['#attached']['js']);
break;
}
}
/**
* Implements hook_preprocess_panels_pane().
*/
function ddbasic_preprocess_panels_pane(&$vars) {
// Suggestions base on sub-type.
$vars['theme_hook_suggestions'][] = 'panels_pane__' . str_replace('-', '__', $vars['pane']->subtype);
$vars['theme_hook_suggestions'][] = 'panels_pane__' . $vars['pane']->panel . '__' . str_replace('-', '__', $vars['pane']->subtype);
if (isset($vars['content'])) {
if (isset($vars['content']['profile_ding_staff_profile']['#title']) && $vars['content']['profile_ding_staff_profile']['#title'] == 'Staff') {
$vars['theme_hook_suggestions'][] = 'panels_pane__user_profile_staff';
}
}
// Suggestions on panel pane.
$vars['theme_hook_suggestions'][] = 'panels_pane__' . $vars['pane']->panel;
// Suggestion for mobile user menu in the header.
if ($vars['pane']->panel == 'header' && $vars['pane']->subtype == 'user_menu') {
$vars['theme_hook_suggestions'] = array('panels_pane__sub_menu__mobile');
}
// Suggestions on menus panes.
if ($vars['pane']->subtype == 'og_menu-og_single_menu_block' || $vars['pane']->subtype == 'menu_block-3') {
$vars['theme_hook_suggestions'][] = 'panels_pane__sub_menu';
$vars['classes_array'][] = 'sub-menu-wrapper';
// Change the theme wrapper for both menu-block and OG menu.
if (isset($vars['content']['#content'])) {
// Menu-block.
$vars['content']['#content']['#theme_wrappers'] = array('menu_tree__sub_menu');
}
else {
// OG menu.
$vars['content']['#theme_wrappers'] = array('menu_tree__sub_menu');
}
}
}
/**
* Implements theme_menu_tree().
*/
function ddbasic_menu_tree__menu_block__1($vars) {
return '<ul class="main-menu">' . $vars['tree'] . '</ul>';
}
/**
* Implements theme_menu_tree().
*/
function ddbasic_menu_tree__menu_block__2($vars) {
return '<ul class="secondary-menu">' . $vars['tree'] . '</ul>';
}
/**
* Implements theme_menu_tree().
*/
function ddbasic_menu_tree__sub_menu($vars) {
return '<ul class="sub-menu">' . $vars['tree'] . '</ul>';
}
/**
* Implements theme_menu_tree().
*/
function ddbasic_menu_tree__menu_tabs_menu($vars) {
return '<ul class="topbar-menu">' . $vars['tree'] . '</ul>';
}
/**
* Implements theme_menu_tree().
*/
function ddbasic_menu_tree__user_menu($vars) {
return '<ul class="system-user-menu">' . $vars['tree'] . '</ul>';
}
/**
* Implements hook_preprocess_views_view_unformatted().
*
* Overwrite views row classes
*/
function ddbasic_preprocess_views_view_unformatted(&$vars) {
// Class names for overwriting.
$row_first = "first";
$row_last = "last";
$view = $vars['view'];
$rows = $vars['rows'];
// Set arrays.
$vars['classes_array'] = array();
$vars['classes'] = array();
// Variables.
$count = 0;
$max = count($rows);
// Loop through the rows and overwrite the classes, its important that the
// $row variable is here, as it's the $id that we need.
foreach ($rows as $id => $row) {
$count++;
$vars['classes'][$id][] = $count % 2 ? 'odd' : 'even';
if ($count == 1) {
$vars['classes'][$id][] = $row_first;
}
if ($count == $max) {
$vars['classes'][$id][] = $row_last;
}
if ($row_class = $view->style_plugin->get_row_class($id)) {
$vars['classes'][$id][] = $row_class;
}
if ($vars['classes'] && $vars['classes'][$id]) {
$vars['classes_array'][$id] = implode(' ', $vars['classes'][$id]);
}
else {
$vars['classes_array'][$id] = '';
}
}
}
/**
* Implements hook_preprocess_user_picture().
*
* Override or insert variables into template user_picture.tpl.php
*
* @TODO: Is there an render array for this, str replacement is not cheap.
* @TODO: Why do we replace and insert span2 thumbnail classes? Aren't they
* bootstrap specific?
*/
function ddbasic_preprocess_user_picture(&$variables) {
// Inject the class we need into the A tag of user_picture.
$variables['user_picture'] = str_replace('<a ', '<a class="span2 thumbnail" ', $variables['user_picture']);
// Inject the class we need into the IMG tag of user_picture.
$variables['user_picture'] = str_replace('<img ', '<img class="pull-left" ', $variables['user_picture']);
}
/**
* Implements hook_preprocess_node().
*
* Override or insert variables into the node templates.
*/
function ddbasic_preprocess_node(&$variables, $hook) {
// Opening hours on library list. but not on the search page.
$path = drupal_get_path_alias();
if (!(strpos($path, 'search', 0) === 0)) {
$hooks = theme_get_registry(FALSE);
if (isset($hooks['opening_hours_week']) && $variables['type'] == 'ding_library') {
$variables['opening_hours'] = theme('opening_hours_week', array('node' => $variables['node']));
}
}
// Add ddbasic_byline to variables.
$variables['ddbasic_byline'] = t('By: ');
// Add event node specific ddbasic variables.
if (isset($variables['content']['#bundle']) && $variables['content']['#bundle'] == 'ding_event') {
// Add event location variables.
if (!empty($variables['content']['field_ding_event_location'][0]['#address']['name_line'])) {
$variables['ddbasic_event_location'] = $variables['content']['field_ding_event_location'][0]['#address']['name_line'] . '<br/>' . $variables['content']['field_ding_event_location'][0]['#address']['thoroughfare'] . ', ' . $variables['content']['field_ding_event_location'][0]['#address']['locality'];
}
else {
// User OG group ref to link back to library.
if (isset($variables['content']['og_group_ref'])) {
$variables['ddbasic_event_location'] = $variables['content']['og_group_ref'];
}
}
// Add event date to variables. A render array is created based on the date
// format "date_only".
$event_date_ra = field_view_field('node', $variables['node'], 'field_ding_event_date', array(
'label' => 'hidden',
'type' => 'date_default',
'settings' => array(
'format_type' => 'ding_date_only',
'fromto' => 'both',
),
));
$variables['ddbasic_event_date'] = $event_date_ra[0]['#markup'];
// Add event time to variables. A render array is created based on the date
// format "time_only".
$event_time_ra = field_view_field('node', $variables['node'], 'field_ding_event_date', array(
'label' => 'hidden',
'type' => 'date_default',
'settings' => array(
'format_type' => 'ding_time_only',
'fromto' => 'both',
),
));
$variables['ddbasic_event_time'] = $event_time_ra[0]['#markup'];
// Show 'Free' text when field_ding_event_price is empty. This has to be
// handled, since the field template is not used in this case.
if (!isset($variables['content']['field_ding_event_price'])) {
$variables['content']['field_ding_event_price'] = t('Free');
}
}
// Add tpl suggestions for node view modes.
if (isset($variables['view_mode'])) {
$variables['theme_hook_suggestions'][] = 'node__view_mode__' . $variables['view_mode'];
}
// Add "read more" links to event, news and e-resource in search result view
// mode.
if ($variables['view_mode'] == 'search_result') {
switch ($variables['node']->type) {
case 'ding_event':
$more_link = array(
'#theme' => 'link',
'#text' => '<i class="icon-chevron-right"></i>',
'#path' => 'node/' . $variables['nid'],
'#options' => array(
'attributes' => array(
'title' => $variables['title'],
),
'html' => TRUE,
),
'#prefix' => '<div class="event-arrow-link">',
'#surfix' => '</div>',
'#weight' => 6,
);
$variables['content']['group_right_col_search']['more_link'] = $more_link;
break;
case 'ding_news':
$more_link = array(
'#theme' => 'link',
'#text' => t('Read more'),
'#path' => 'node/' . $variables['nid'],
'#options' => array(
'attributes' => array(
'title' => $variables['title'],
),
'html' => FALSE,
),
'#prefix' => '<span class="news-link">',
'#surfix' => '</span>',
'#weight' => 6,
);
$variables['content']['group_right_col_search']['more_link'] = $more_link;
break;
case 'ding_eresource':
$more_link = array(
'#theme' => 'link',
'#text' => t('Read more'),
'#path' => 'node/' . $variables['nid'],
'#options' => array(
'attributes' => array(
'title' => $variables['title'],
),
'html' => FALSE,
),
'#prefix' => '<span class="eresource-link">',
'#surfix' => '</span>',
'#weight' => 6,
);
$variables['content']['group_right_col_search']['more_link'] = $more_link;
break;
}
}
// For search result view mode move title into left col. group.
if (isset($variables['content']['group_right_col_search'])) {
$variables['content']['group_right_col_search']['title'] = array(
'#theme' => 'link',
'#text' => decode_entities($variables['title']),
'#path' => 'node/' . $variables['nid'],
'#options' => array(
'attributes' => array(
'title' => $variables['title'],
),
'html' => FALSE,
),
'#prefix' => '<h2>',
'#suffix' => '</h2>',
);
}
// Add updated to variables.
$variables['ddbasic_updated'] = t('!datetime', array(
'!datetime' => format_date(
$variables['node']->changed,
$type = 'long',
$format = '',
$timezone = NULL,
$langcode = NULL
))
);
// Modified submitted variable.
if ($variables['display_submitted']) {
$variables['submitted'] = t('!datetime', array(
'!datetime' => format_date(
$variables['created'],
$type = 'long',
$format = '',
$timezone = NULL,
$langcode = NULL
))
);
}
}
/**
* Implements template_preprocess_field().
*/
function ddbasic_preprocess_field(&$vars, $hook) {
// Get current view mode (teaser).
$view_mode = $vars['element']['#view_mode'];
$field_name = $vars['element']['#field_name'];
// Add suggestion for ddbasic specific field.
$vars['theme_hook_suggestions'][] = 'field__ddbasic';
// Add suggestion for ddbasic field with specific name.
$vars['theme_hook_suggestions'][] = 'field__ddbasic_' . $field_name;
// Add suggestion for ddbasic field in specific view mode.
$vars['theme_hook_suggestions'][] = 'field__ddbasic_' . $view_mode;
// Stream line tags in view modes using the same tpl.
if ($vars['element']['#field_type'] == 'taxonomy_term_reference') {
$vars['theme_hook_suggestions'][] = 'field__ddbasic_tags__' . $view_mode;
}
// Ensure that all OG group ref field are the same.
if ($field_name == 'ding_event_groups_ref' || $field_name == 'ding_news_groups_ref' || $field_name == 'og_group_ref') {
$vars['theme_hook_suggestions'][] = 'field__og_group_ref';
// Add classes to get label correctly formatted.
foreach ($vars['items'] as $id => $item) {
$vars['items'][$id]['#options'] = array(
'attributes' => array(
'class' => array(
'label',
'label_info',
),
),
);
}
}
// Clean up fields in search result view mode aka. search result page.
if ($view_mode == 'search_result') {
// Add suggestion that only hits the search result page.
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $view_mode;
switch ($vars['element']['#field_name']) {
case 'ting_author':
case 'ting_abstract':
case 'ting_subjects':
$vars['classes_array'] = array('content');
break;
case 'ting_title':
$vars['classes_array'] = array('heading');
break;
}
}
// Make suggestion for the availability on the search result page.
if ($vars['element']['#field_type'] == 'ting_collection_types' &&
$vars['element']['#formatter'] == 'ding_availability_with_labels') {
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . 'search_result';
}
// Add class to library OG ref on staff profiles only.
if ($vars['element']['#bundle'] == 'ding_staff_profile') {
$staff_fields = array(
'og_group_ref',
'field_ding_staff_department',
'field_ding_staff_email',
'field_ding_staff_phone',
'field_ding_staff_work_areas',
);
if (in_array($field_name, $staff_fields)) {
$vars['theme_hook_suggestions'][] = 'field__ding_staff__content_field';
// Ensure that department is not add label info.
if ($field_name == 'field_ding_staff_department' || $field_name == 'og_group_ref') {
foreach ($vars['items'] as $id => $item) {
// This as little hack to make the user interface look better.
$vars['items'][$id]['#options']['no_label'] = TRUE;
}
}
}
if ($field_name == 'og_group_ref') {
$vars['classes_array'][] = 'field-name-ding-library-name';
}
}
}
/**
* Implements theme_link().
*
* Adds a class "label" to all link in taxonomies.
*
* @see theme_link()
*/
function ddbasic_link($variables) {
if (isset($variables['options']['entity_type']) && $variables['options']['entity_type'] == 'taxonomy_term') {
if (!isset($variables['options']['no_label'])) {
// Add classes label and label-info.
if (!isset($variables['options']['attributes']['class'])) {
$variables['options']['attributes']['class'] = array();
}
$variables['options']['attributes']['class'][] = 'label';
$variables['options']['attributes']['class'][] = 'label-info';
}
}
return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a>';
}
/**
* Render callback.
*
* Remove panels div separator.
*/
function ddbasic_panels_default_style_render_region($vars) {
$output = '';
$output .= implode('', $vars['panes']);
return $output;
}
/**
* Implements template_preprocess_user_profile().
*/
function ddbasic_preprocess_user_profile(&$variables) {
$variables['user_profile']['summary']['member_for']['#access'] = FALSE;
}
/**
* Implements template_preprocess_entity().
*
* Runs an entity specific preprocess function, if it exists.
*/
function ddbasic_preprocess_entity(&$variables, $hook) {
$function = __FUNCTION__ . '_' . $variables['entity_type'];
if (function_exists($function)) {
$function($variables, $hook);
}
}
/**
* Profile2 specific implementation of template_preprocess_entity().
*/
function ddbasic_preprocess_entity_profile2(&$variables) {
// Add staff position as a renderable field without label for subheader.
if ($variables['profile2']->type == 'ding_staff_profile') {
if (isset($variables['content']['group_contactinfo']['field_ding_staff_position'])) {
$staff_position = $variables['content']['group_contactinfo']['field_ding_staff_position'];
$staff_position['#label_display'] = 'hidden';
$variables['position_no_label'] = $staff_position;
}
else {
$variables['position_no_label'] = FALSE;
}
}
}
/**
* Implements theme_menu_link().
*/
function ddbasic_menu_link($vars) {
$element = $vars['element'];
// Render any sub-links/menus.
$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',
);
// Filter classes.
$element['#attributes']['class'] = ddbasic_remove_default_link_classes($element['#attributes']['class']);
// Make sure text string is treated as html by l function.
$element['#localized_options']['html'] = TRUE;
$link = l('<span>' . $element['#title'] . '</span>', $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $link . $sub_menu . "</li>\n";
}
/**
* Implements theme_menu_link().
*
* Add specific markup for top-bar menu exposed as menu_block_4.
*/
function ddbasic_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';
// 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';
break;
case 'node':
// Special placeholder for mobile user menu. Fall through to next case.
$element['#localized_options']['attributes']['class'][] = 'default-override';
case 'user':
$title_prefix = '<i class="icon-user"></i>';
// 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':
$title_prefix = '<i class="icon-signout"></i>';
$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:
$title_prefix = '<i class="icon-align-justify"></i>';
$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";
}
/**
* Used to strip default class names from menu links.
*
* @param array $classes
* An array of class attributes.
*
* @return array
* Classes that are left.
*/
function ddbasic_remove_default_link_classes($classes) {
if (!isset($classes)) {
return FALSE;
}
// Remove classes.
$remove = array();
// Remove .leaf.
if (theme_get_setting('ddbasic_classes_menu_leaf')) {
$remove[] .= "leaf";
}
// Remove .has-children.
if (theme_get_setting('ddbasic_classes_menu_has_children')) {
$remove[] .= "has-children";
}
// Remove .collapsed, .expanded and expandable.
if (theme_get_setting('ddbasic_classes_menu_collapsed')) {
$remove[] .= "collapsed";
$remove[] .= "expanded";
$remove[] .= "expandable";
}
// Remove the classes.
if ($remove) {
$classes = array_diff($classes, $remove);
}
// Remove menu-mlid-[NUMBER].
if (theme_get_setting('ddbasic_classes_menu_items_mlid')) {
$classes = preg_grep('/^menu-mlid-/', $classes, PREG_GREP_INVERT);
}
return $classes;
}
/**
* Allows us to add script plugins to the theme via theme settings.
*
* Ex. add a javascript depending on the settings in the theme.
*/
function ddbasic_load_plugins() {
$theme_path = drupal_get_path('theme', 'ddbasic');
// If sticky menus is enabled in the theme load it.
if (theme_get_setting('main_menu_sticky')) {
// Add variable to js so we can check if it is set.
drupal_add_js(array('ddbasic' => array('main_menu_sticky' => theme_get_setting('main_menu_sticky'))), 'setting');
}
// If equalize is enabled in the theme load it.
if (theme_get_setting('load_equalize')) {
// Add the script.
drupal_add_js($theme_path . '/scripts/equalize.min.js');
// Add variable to js so we can check if it is set.
drupal_add_js(array('ddbasic' => array('load_equalize' => theme_get_setting('load_equalize'))), 'setting');
}
}
/**
* Implements hook_theme_script().
*
* Since Drupal 7 does not (yet) support the 'browser' option in drupal_add_js()
* ddbasic provides a way to load scripts inside conditional comments.
* This function wraps a file in script elements and returns a string.
*/
function ddbasic_theme_script($filepath) {
$script = '';
// We need the default query string for cache control finger printing.
$query_string = variable_get('css_js_query_string', '0');
if (file_exists($filepath)) {
$file = file_create_url($filepath);
$script = '<script src="' . $file . '?' . $query_string . '"></script>';
}
return $script;
}
/**
* Return the info file array for a particular theme, usually the active theme.
*
* Simple wrapper function for list_themes().
*
* @param string $theme_name
* Name of the current theme.
*/
function ddbasic_get_info($theme_name) {
$info = &drupal_static(__FUNCTION__, array());
if (empty($info)) {
$themes = list_themes();
foreach ($themes as $key => $value) {
if ($theme_name == $key) {
$info = $themes[$theme_name]->info;
}
}
}
return $info;
}
/**
* Implements theme_item_list().
*
* This is the default theme function. With the wrapper div removed.
*/
function ddbasic_item_list($variables) {
$items = $variables['items'];
$title = $variables['title'];
$type = $variables['type'];
$attributes = $variables['attributes'];
$output = '';
// Only output the list container and title, if there are any list items.
// Check to see whether the block title exists before adding a header.
// Empty headers are not semantic and present accessibility challenges.
if (isset($title) && $title !== '') {
$output .= '<h3>' . $title . '</h3>';
}
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items);
foreach ($items as $i => $item) {
$attributes = array();
$children = array();
$data = '';
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
$data = $value;
}
elseif ($key == 'children') {
$children = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$data = $item;
}
if (count($children) > 0) {
// Render nested list.
$data .= theme_item_list(array(
'items' => $children,
'title' => NULL,
'type' => $type,
'attributes' => $attributes,
));
}
if ($i == 0) {
$attributes['class'][] = 'first';
}
if ($i == $num_items - 1) {
$attributes['class'][] = 'last';
}
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
}
$output .= "</$type>";
}
return $output;
}
/**
* Implements hook_process_page().
*/
function ddbasic_process_page(&$vars) {
// Hook into color.module
if (module_exists('color')) {
_color_page_alter($vars);
}
}
/**
* Implements hook_preprocess_ting_object().
*
* Adds wrapper classes to the different groups on the ting object.
*/
function ddbasic_preprocess_ting_object(&$vars) {
if (isset($vars['elements']['#view_mode']) && $vars['elements']['#view_mode'] == 'full') {
switch ($vars['elements']['#entity_type']) {
case 'ting_object':
$content = $vars['content'];
$vars['content'] = array();
if (isset($content['group_ting_object_left_column']) && $content['group_ting_object_left_column']) {
$vars['content']['ting-object'] = array(
'#prefix' => '<div class="ting-object-wrapper">',
'#suffix' => '</div>',
'content' => array(
'#prefix' => '<div class="ting-object-inner-wrapper">',
'#suffix' => '</div>',
'left_column' => $content['group_ting_object_left_column'],
'right_column' => $content['group_ting_object_right_column'],
),
);
unset($content['group_ting_object_left_column']);
unset($content['group_ting_object_right_column']);
}
if (isset($content['group_material_details']) && $content['group_material_details']) {
$vars['content']['material-details'] = array(
'#prefix' => '<div class="ting-object-wrapper">',
'#suffix' => '</div>',
'content' => array(
'#prefix' => '<div class="ting-object-inner-wrapper">',
'#suffix' => '</div>',
'details' => $content['group_material_details'],
),
);
unset($content['group_material_details']);
}
if (isset($content['group_holdings_available']) && $content['group_holdings_available']) {
$vars['content']['holdings-available'] = array(
'#prefix' => '<div class="ting-object-wrapper">',
'#suffix' => '</div>',
'content' => array(
'#prefix' => '<div class="ting-object-inner-wrapper">',
'#suffix' => '</div>',
'details' => $content['group_holdings_available'],
),
);
unset($content['group_holdings_available']);
}
if (isset($content['group_periodical_issues']) && $content['group_periodical_issues']) {
$vars['content']['periodical-issues'] = array(
'#prefix' => '<div class="ting-object-wrapper">',
'#suffix' => '</div>',
'content' => array(
'#prefix' => '<div class="ting-object-inner-wrapper">',
'#suffix' => '</div>',
'details' => $content['group_periodical_issues'],
),
);
unset($content['group_periodical_issues']);
}
if (isset($content['group_on_this_site']) && $content['group_on_this_site']) {
$vars['content']['on_this_site'] = array(
'#prefix' => '<div class="ting-object-wrapper">',
'#suffix' => '</div>',
'content' => array(
'#prefix' => '<div id="ting_reference" class="ting-object-inner-wrapper">',
'#suffix' => '</div>',
'details' => $content['group_on_this_site'],
),
);
unset($content['group_on_this_site']);
}
if (isset($content['ting_relations']) && $content['ting_relations']) {
$vars['content']['ting-relations'] = array(
'content' => array(
'details' => $content['ting_relations'],
),
);
unset($content['ting_relations']);
}
// Move the reset over if any have been defined in the UI.
if (!empty($content)) {
$vars['content'] += $content;
}