/
template.php
923 lines (840 loc) · 33.6 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
<?php
/**
* @file
* Theme and preprocess functions for GSB Theme.
*/
/**
* Overrides theme_date_all_day_label().
*/
function gsb_theme_date_all_day_label($variables) {
return '';
}
/**
* Overrides theme_date_display_range().
*/
function gsb_theme_date_display_range($variables) {
return $variables['date1'] . ' – ' . $variables['date2'];
return $variables['time1'] . ' – ' . $variables['time2'];
}
/**
* Overrides theme_breadcrumb().
*/
//function gsb_theme_breadcrumb($variables) {
// $breadcrumb = $variables['breadcrumb'];
//
// // Remove the breadcrumb on the 'Search' page
// $root_path = menu_tab_root_path();
// if ($root_path == 'gsearch' || $root_path == 'exec-ed/search' || $root_path == 'seed/search') {
// unset($variables['breadcrumb']);
// return;
// }
//
// // We can't implement hook_menu_breadcrumb_alter because breadcrumbs_by_path
// // are loaded on page_build.
// // We assume that Home link is first and remove it.
// array_shift($breadcrumb);
//
// if (!empty($breadcrumb)) {
// // Provide a navigational heading to give context for breadcrumb links to
// // screen-reader users. Make the heading invisible with .element-invisible.
// $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
// $output .= '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>';
// return $output;
// }
//}
function gsb_theme_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
// Remove the breadcrumb on the 'Search' page
$root_path = menu_tab_root_path();
if ($root_path == 'coveo-search-page' || $root_path == 'gsearch' || $root_path == 'exec-ed/search' || $root_path == 'seed/search') {
unset($variables['breadcrumb']);
return;
}
// We can't implement hook_menu_breadcrumb_alter because breadcrumbs_by_path
// are loaded on page_build.
// We assume that Home link is first and remove it.
array_shift($breadcrumb);
$crumbs='';
if (!empty($breadcrumb)) {
$crumbs_prefix = '<div class="breadcrumb" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">';
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$crumbs_prefix .= '<h2 class="element-invisible">' . t('You are here') . '</h2>';
foreach($breadcrumb as $value) {
$value = preg_replace('/(<a[^>]*>)(.*)(<\/a>)/i', '$1<span itemprop="title">$2</span>$3', $value);
$value = str_replace('<a href', '<a itemprop="url" href', $value);
if (empty($crumbs)){
$crumbs .= $value ;
} else {
$crumbs .= ' › ' . $value ;
}
}
$crumbs = $crumbs_prefix . $crumbs . '</div>';
}
return $crumbs;
}
/**
* Implements hook_form_FORM_ID_alter() for views_exposed_form().
*/
function gsb_theme_form_views_exposed_form_alter(&$form, &$form_state) {
$search_form_ids = array(
'views-exposed-form-search-news-news-list',
'views-exposed-form-research-papers-panel-pane-1',
'views-exposed-form-search-faculty-panel-pane-1'
);
$filter_form_ids = array(
'views-exposed-form-case-study-filters-case-study-list',
'views-exposed-form-club-filters-club-list',
'views-exposed-form-news-list-news-list',
'views-exposed-form-media-mention-filters-media-mention-list',
'views-exposed-form-publications-filters-publication-list',
'views-exposed-form-research-paper-filters-research-paper-list',
'views-exposed-form-faculty-filters-faculty-list',
'views-exposed-form-gsb-working-paper-listing-working-paper-list',
'views-exposed-form-gsb-case-listing-case-listing',
'views-exposed-form-gsb-book-listing-book-listing',
'views-exposed-form-seed-research-listing-seed-research-pane',
'views-exposed-form-gsb-publications-listing-publications-listing',
'views-exposed-form-gsb-act-project-listing-panel-pane-1',
'views-exposed-form-gsb-act-project-listing-panel-pane-2',
'views-exposed-form-gsb-act-project-listing-panel-pane-3',
'views-exposed-form-gsb-event-main-event-list-pane',
'views-exposed-form-admission-events-mba-admission-panel-pane',
'views-exposed-form-gsb-all-research-listing-all-research-panel-pane',
'views-exposed-form-admission-events-msx-admission-panel-pane',
'views-exposed-form-msx-fellows-list',
'views-exposed-form-gsb-act-project-listing-panel-pane-1',
'views-exposed-form-msx-fellows-graduation-year-list'
);
if ($is_search_form = in_array($form['#id'], $search_form_ids)) {
// Add placeholder text.
if (!empty($form['keyword'])) {
$form['keyword']['#attributes']['placeholder'] = t('search within');
}
else if (!empty($form['search'])) {
$form['search']['#attributes']['placeholder'] = t('search within');
}
$form['#attributes']['class'][] = 'gsb-views-exposed-search';
}
if ($is_filter_form = in_array($form['#id'], $filter_form_ids)) {
$form['#attributes']['class'][] = 'gsb-views-exposed-filter';
}
if ($is_search_form || $is_filter_form) {
$form['#attributes']['class'][] = 'gsb-views-exposed-form';
}
$split_search_views = array(
'club_filters',
'faculty_filters',
'gsb_event',
'gsb_working_paper_listing',
'gsb_case_listing',
'gsb_book_listing',
'gsb_publications_listing',
'admission_events',
'publication_filters',
'msx_fellows',
'gsb_act_project_listing',
'seed_research_listing'
);
if (in_array($form_state['view']->name, $split_search_views)) {
// Trigger the alternate template, see gsb_theme_preprocess_views_exposed_form().
$form['#gsb_theme_search_button'] = TRUE;
// Exclude the search text field from auto-submit.
$form['search']['#attributes']['class'][] = 'ctools-auto-submit-exclude';
}
// Seed Research Listing placeholder text.
if ($form['#id'] == 'views-exposed-form-seed-research-listing-seed-research-pane') {
// Add placeholder text.
$form['field_search_field_value']['#attributes']['placeholder'] = t('Search by title or keyword');
}
// Faculty listing placeholder text.
if ($form['#id'] == 'views-exposed-form-faculty-filters-faculty-list') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, research interests, or other keywords');
}
// Working paper listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-working-paper-listing-working-paper-list') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by title, author, date, topic, or other keywords');
}
// Case study listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-case-listing-case-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by title, author, date, topic, or other keywords');
}
// Book listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-book-listing-book-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by title, author, year, topic, or other keywords');
}
// Publication listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-publications-listing-publications-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by title, author, year, journal, topic, or other keywords');
}
// Announcement and school story mixed listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-announcement-school-listing-annssh-stories-list') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, program, date, topic, or other keywords');
}
// Ranking listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-ranking-listing-ranking-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by publication, date, or other keywords');
}
// Faculty insights listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-faculty-insights-listing-faculty-insights-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, date, topic, or other keywords');
}
// In the media listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-in-the-media-listing-in-the-media-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, program, date, topic, or other keywords');
}
// Alumni stories listing placeholder text.
if ($form['#id'] == 'views-exposed-form-stories-alumni-stories-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, program, class year, topic, or other keywords');
}
// Giving stories listing placeholder text.
if ($form['#id'] == 'views-exposed-form-stories-giving-stories-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, program, class year, topic, or other keywords');
}
// Alumni book listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-book-listing-alumni-book-listing') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, program, class year, topic, or other keywords');
}
// Clubs listing placeholder text.
if ($form['#id'] == 'views-exposed-form-club-filters-club-list') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search Stanford GSB clubs');
}
// Main event listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-event-main-event-list-pane') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search for upcoming events');
}
// MBA admission event listing after build customizations.
if ($form['#id'] == 'views-exposed-form-admission-events-mba-admission-panel-pane') {
$form['#after_build'][] = 'gsb_theme_admission_events_mba_list_after_build';
}
// All publications listing.
if ($form['#id'] == 'views-exposed-form-gsb-all-research-listing-all-research-panel-pane') {
// Add placeholder text.
$form['field_search_field_value']['#attributes']['placeholder'] = t('Search by title, author, journal, topic, or other keywords');
}
// MSx admission events.
if ($form['#id'] == 'views-exposed-form-admission-events-msx-admission-panel-pane') {
// Add placeholder text.
$form['#after_build'][] = 'gsb_theme_admission_events_mba_list_after_build';
$form['search']['#attributes']['placeholder'] = t('Search by location, title, or other keywords');
}
// Faculty listing placeholder text.
if ($form['#id'] == 'views-exposed-form-msx-fellows-list') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by name, research interests, or other keywords');
}
// Faculty listing placeholder text for msx-fellows-graduation-year-list.
if ($form['#id'] == 'views-exposed-form-msx-fellows-graduation-year-list') {
// Add placeholder text.
$form['field_search_field_value']['#attributes']['placeholder'] = t('Search by name, research interests, or other keywords');
}
// Alumni ACT Project listing placeholder text.
if ($form['#id'] == 'views-exposed-form-gsb-act-project-listing-panel-pane-1') {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by organization, team member, location, or other keywords');
}
}
function gsb_theme_admission_events_mba_list_after_build($form, &$form_state) {
// Add placeholder text.
$form['search']['#attributes']['placeholder'] = t('Search by location, title, or other keywords');
// Alter the date field labels
$form['date_search']['min']['#title'] = t('Date from');
$form['date_search']['max']['#title'] = t('to');
$form['secondary']['date_search']['#bef_position'] = 9;
$form['secondary']['date_search']['min']['#title'] = t('Date from');
$form['secondary']['date_search']['max']['#title'] = t('to');
$form['secondary']['date_search']['value']['date']['#title'] = "Date from";
unset($form['secondary']['date_search']['value']['date']['#title_display']);
$form['secondary']['field_event_date_value']['value']['date']['#title'] = "to";
unset($form['secondary']['field_event_date_value']['value']['date']['#title_display']);
// Hide the date descriptions
unset($form['date_search']['max']['date']['#description'], $form['date_search']['min']['date']['#description']);
return $form;
}
/**
* Preprocess html.
*
* Load selectivizr library for support IE 8, 7 pseudo classes.
* Add meta for GTM site owner verification.
*/
function gsb_theme_preprocess_html(&$variables) {
global $base_url;
// Add meta for GTM site owner verification
$meta_google_verification = array(
'#tag' => 'meta',
'#attributes' => array(
'name' => 'google-site-verification',
'content' => 'u7Z-lHDsA7zpu0SiM1e_255JVF1ht59Oly6PSgvQqxA',
)
);
// Add header meta tag for GTM site owner verification
drupal_add_html_head($meta_google_verification, 'meta_google_verification');
$selectivizr = array(
'#tag' => 'script',
'#attributes' => array(
'src' => $base_url . '/' . drupal_get_path('theme', 'gsb_theme') . '/js/libs/selectivizr-min.js',
),
'#prefix' => '<!--[if lt IE 9]>',
'#suffix' => '</script><![endif]-->',
);
drupal_add_html_head($selectivizr, 'selectivzr');
// Setup fb instant articles meta tag
$meta_fb_instant_articles = array(
'#tag' => 'meta',
'#attributes' => array(
'property' => 'fb:pages',
'content' => '208357009185713',
)
);
// Add header meta tag for fb instant articles
drupal_add_html_head($meta_fb_instant_articles, 'meta_fb_instant_articles');
// Normally template_preprocess_html() will add classes based on the URL, but
// if this is a node page we have to check the request_uri() directly.
$allowed_paths = array(
'programs',
'stanford-gsb-experience',
'library',
'newsroom',
'insights',
'alumni',
'organizations',
'faculty-research',
'events',
'exec-ed',
'seed',
);
$normalized_arg = arg(0);
$parsed_url = drupal_parse_url(request_uri());
$path = explode('/', trim($parsed_url['path'], '/'));
if (isset($path[0]) && in_array($path[0], $allowed_paths) && $normalized_arg == 'node') {
foreach (theme_get_suggestions($path, 'page', '-') as $arg) {
$variables['classes_array'][] = drupal_html_class($arg);
}
}
if (user_access('administer panelizer node page content')) {
drupal_add_css(drupal_get_path('theme', 'gsb_theme') . '/css/admin-modal/admin-modal.css');
}
if (drupal_get_http_header('status') == "404 Not Found") {
$variables['classes_array'][] = 'page-error page-404';
}
if (drupal_get_http_header('status') == "403 Forbidden") {
$variables['classes_array'][] = 'page-error page-403';
}
if ($display = panels_get_current_page_display()) {
$variables['classes_array'][] = 'panels-layout-' . $display->layout;
}
if (!empty($parsed_url['path']) && strpos($parsed_url['path'], '/seed/search') !== false) {
$variables['classes_array'][] = 'page-gsearch';
}
else if (!empty($parsed_url['path']) && strpos($parsed_url['path'], '/exec-ed/search') !== false) {
$variables['classes_array'][] = 'page-gsearch';
}
}
/**
* Preprocess page.
*/
function gsb_theme_preprocess_page(&$variables) {
global $theme_info;
// turn off google indexing for the page title if we are on the email contact form
if (!empty($variables['theme_hook_suggestions'][0] && $variables['theme_hook_suggestions'][0] == 'page__email_contact')) {
$variables['title_prefix'] = array(
'#type' => 'markup',
'#markup' => '<!--googleoff: index--><!--googleoff: snippet-->',
);
$variables['title_suffix'] = array(
'#type' => 'markup',
'#markup' => '<!--googleon: snippet--><!--googleon: index-->',
);
}
// load homepage viewport sizing and custom scrollbar
if (request_uri() === url('<front>')) {
drupal_add_js(drupal_get_path('theme', 'gsb_theme') . '/js/landing-viewport.js', array(
'type' => 'file',
'scope' => 'header',
'weight' => 4,
));
}
// 403 page
if(drupal_get_http_header('status') == "403 Forbidden") {
$variables['theme_hook_suggestions'][] = 'page__403';
}
// 404 page
if (drupal_get_http_header('status') == "404 Not Found") {
$variables['theme_hook_suggestions'][] = 'page__404';
}
$object = menu_get_object();
if ($object && !empty($object->path['alias'])) {
if ($object->path['alias'] == 'exec-ed/admission') {
$variables['theme_hook_suggestions'][] = 'page__ee_program_admission';
}
}
if (!empty($_GET['q']) && $_GET['q'] == 'coveo-search-page/') {
$variables['theme_hook_suggestions'][] = 'page__coveo_search';
}
// Add search and event link to main navigation
$variables['global_search'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'global-search',
),
),
'search' => module_invoke('gsb_coveo_search', 'block_view', 'coveo_search_block_form'),
);
// Add css stylesheets based on the following settings in gsb_theme.info:
// ; GSB Styles
// gsb_styles[path][events][] = eventlanding.css
// gsb_styles[path][events/*][] = eventsection.css
$page_path = drupal_get_path_alias();
if (!empty($theme_info->info['gsb_styles']['path'])) {
$module_path = drupal_get_path('theme', $theme_info->name);
foreach($theme_info->info['gsb_styles']['path'] as $style_path => $paths) {
if (!empty($paths)) {
foreach($paths as $key => $sheet) {
if (drupal_match_path($page_path, $style_path)) {
drupal_add_css($module_path . '/' . $sheet);
}
}
}
}
}
}
/**
* Preprocess exposed filters forms.
*/
function gsb_theme_preprocess_views_exposed_form(&$variables) {
// Add the 'Filter by' to the filter title on the admissions events pane
if ($variables['form']['#id'] == 'views-exposed-form-admission-events-pane') {
$variables['filter_title'] = t('Filter by');
}
if (isset($variables['form']['#gsb_theme_search_button'])) {
// Allow for an alternate template.
$variables['theme_hook_suggestions'][] = 'views_exposed_form__split_search';
$variables['search_widgets'] = array();
$search_form_name = 'filter-field_search_field_value';
// Split the search widget to go above the search button.
if (isset($variables['widgets'][$search_form_name])) {
$variables['search_widgets'][$search_form_name] = $variables['widgets'][$search_form_name];
unset($variables['widgets'][$search_form_name]);
}
}
}
/**
* Implements hook_form_alter()
* modifies the action for the exec-ed and seed pages google_appliance_block_form
* also, adds class for add content forms
*/
function gsb_theme_form_alter(&$form, &$form_state, $form_id) {
$form['#attached']['js'][drupal_get_path('theme', 'gsb_theme') . '/js/gsb_forms.js'] = array();
if ($form_id == 'google_appliance_block_form') {
if (strpos($form['#action'], '/exec-ed') === 0) {
$form['#action'] = '/exec-ed/search';
}
if (strpos($form['#action'], '/seed') === 0) {
$form['#action'] = '/seed/search';
}
}
if ($form_id == 'views_content_views_panes_content_type_edit_form' || $form_id == 'ctools_block_content_type_edit_form' || $form_id == 'fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form') {
$form['#attributes']['class'][] = 'modal-add-content-form';
$form['buttons']['#weight'] = 500;
}
}
/**
* Implements hook_preprocess_HOOK() for theme_field().
*/
function gsb_theme_preprocess_field(&$variables, $hook) {
// Check if the element is: field_related_faculty
// And if it is empty, then hide the element by adding the 'hide_this' css class to
if ($variables['element']['#field_name'] == 'field_related_faculty') {
$item_id = $variables['element']['#items'][0]['value'];
if (empty($variables['element'][0]['entity']['field_collection_item'][$item_id]['field_person_fac_single_ref'])) {
$variables['classes_array'][] = 'hide_this';
}
}
// remove the field_image_single_public image if associated with a person reference (non-other option)
if ($variables['element']['#field_name'] = 'field_image_single_public' && !empty($variables['element']['#formatter']) && $variables['element']['#formatter'] == 'field_collection_fields') {
if ($variables['element']['#bundle'] == 'program_instance') {
foreach($variables['element'] as $key => $item) {
if (is_int($key)) {
$fc_id = $variables['element']['#items'][$key]['value'];
if (!empty($item['entity']['field_collection_item'][$fc_id]) && !empty($item['entity']['field_collection_item'][$fc_id]['field_person_fac_single_ref'])) {
unset($variables['items'][$key]['entity']['field_collection_item'][$fc_id]['field_image_single_public']);
}
}
}
}
}
// Ensure custom DS labels are used for link label formatters.
if (isset($variables['ds-config']['lb']) && $variables['element']['#formatter'] == 'link_label') {
foreach ($variables['items'] as &$item) {
if (isset($item['#field'])) {
$item['#field']['label'] = $variables['ds-config']['lb'];
}
}
}
// Remove 'clearfix' class from case fields
$element = $variables['element'];
$key = array_search('clearfix', $variables['classes_array']);
if ($element['#bundle'] == 'case' && $key !== FALSE) {
unset($variables['classes_array'][$key]);
}
}
/**
* Implements theme_menu_link().
*/
function gsb_theme_preprocess_menu_link(&$variables) {
// Need to remove any menu minipanels code on anything that isn't the main
// menu.
if ($variables['element']['#original_link']['menu_name'] !== 'main-menu' &&
$variables['element']['#original_link']['menu_name'] !== 'menu-executive-education-mega-me' &&
$variables['element']['#original_link']['menu_name'] !== 'menu-mega-menu-seed') {
unset($variables['element']['#localized_options']['menu_minipanels_hover']);
}
}
/**
* Implements hook_process_HOOK() for node.tpl.php.
*/
function gsb_theme_preprocess_node(&$variables) {
global $theme_info;
// Add css stylesheets based on the following settings in gsb_theme.info:
// ; GSB Styles
// gsb_styles[node][event][] = css/conditionals/event/test.css
if (!empty($theme_info->info['gsb_styles']['node'])) {
$path = drupal_get_path('theme', $theme_info->name);
foreach($theme_info->info['gsb_styles']['node'] as $bundle => $stylesheets) {
if ($bundle == $variables['type'] && !empty($stylesheets)) {
foreach($stylesheets as $sheet) {
drupal_add_css($path . '/' . $sheet);
}
}
}
}
}
/**
* Implements hook_process_HOOK() for node.tpl.php.
*/
function gsb_theme_process_node(&$variables, $hook) {
// For teaser listings, if the right column is not empty, add a specific class.
$types = array(
'book',
'event',
'announcement',
'school_story',
'offsite_school_story',
'idea_story',
'offsite_idea_story',
);
$view_modes = array(
'teaser_listing',
'event_listing',
'news_listing',
'compact',
'expanded',
'main_list'
);
_gsb_theme_prepare_two_column_classes($variables['type'], $types, $view_modes, $variables);
}
/**
* Implements hook_preprocess_HOOK() for entities.
*/
function gsb_theme_process_entity(&$variables, $hook) {
if ($variables['entity_type'] == 'field_collection_item' && isset($variables['field_collection_item'])) {
$types = array(
'field_featured_item',
);
$view_modes = array(
'full',
);
_gsb_theme_prepare_two_column_classes($variables['field_collection_item']->bundle(), $types, $view_modes, $variables);
}
}
/**
* Prepares a template for two columns.
*
* @param string $bundle
* The bundle of the entity.
* @param array $bundles
* The bundles to prepare.
* @param array $view_modes
* The view modes to prepare.
* @param array $variables
* The array of variables for the template.
*/
function _gsb_theme_prepare_two_column_classes($bundle, $bundles, $view_modes, &$variables) {
if (in_array($bundle, $bundles) && in_array($variables['view_mode'], $view_modes)) {
if (!empty($variables['right'])) {
$variables['left_classes'] .= ' second-column';
}
}
}
/**
* Implements hook_preprocess_views_view().
*/
function gsb_theme_preprocess_views_view(&$variables) {
global $theme_info;
// Add css stylesheets based on the following settings in gsb_theme.info:
// ; GSB Styles
// gsb_styles[view][my_view_name][] = css/conditionals/event/event-view-mode-main-list.css
// gsb_styles[view][my_view_name][display_name][] = cssJustForId.css
if (!empty($theme_info->info['gsb_styles']['view']) && !empty($variables['view'])) {
$path = drupal_get_path('theme', $theme_info->name);
foreach ($theme_info->info['gsb_styles']['view'] as $view_name => $display_names) {
if ($view_name == $variables['view']->name) {
foreach($display_names as $display_name => $stylesheets) {
if (is_int($display_name)) {
if (is_string($stylesheets)) {
$sheet = $stylesheets;
drupal_add_css($path . '/' . $sheet);
}
}
else if ($variables['view']->current_display === $display_name) {
foreach($stylesheets as $sheet) {
drupal_add_css($path . '/' . $sheet);
}
}
}
}
}
}
}
/**
* Clean up the panel pane variables for the template.
*/
function gsb_theme_preprocess_panels_pane(&$variables) {
global $theme_info;
// Add css stylesheets based on the following settings in gsb_theme.info:
// ; GSB Styles
// gsb_styles[fpp][name][] = mypanelpane.css
// gsb_styles[fpp][links][my_viewmode][] = css/conditionals
if (!empty($theme_info->info['gsb_styles']['fpp'])) {
$path = drupal_get_path('theme', $theme_info->name);
foreach ($theme_info->info['gsb_styles']['fpp'] as $fpp_name => $view_modes) {
if (!empty($variables['content']['#bundle']) && $fpp_name == $variables['content']['#bundle']) {
if (!empty($view_modes)) {
foreach($view_modes as $view_mode => $stylesheets) {
if (is_int($view_mode)) {
if (is_string($stylesheets)) {
$sheet = $stylesheets;
drupal_add_css($path . '/' . $sheet);
}
}
else if ($variables['content']['#view_mode'] == $view_mode) {
foreach($stylesheets as $sheet) {
drupal_add_css($path . '/' . $sheet);
}
}
}
}
}
}
}
}
/**
* Implements hook_preprocess_HOOK() for views-view-table.tpl.php.
*/
function gsb_theme_preprocess_views_view_table(&$variables) {
// A list of table views that should be responsive.
$responsive_views = array(
'admission_events',
);
if (in_array($variables['view']->name, $responsive_views)) {
$variables['classes_array'][] = 'responsive';
}
}
/**
* Themed output of the footnotes list appearing at at [footnotes]
*
* Accepts an array containing an ordered listing of associative arrays, each
* containing values on the following keys:
* text - the raw unprocessed text extracted from within the [fn] tag
* text_clean - a sanitized version of the previous, may be used as HTML attribute value
* value - the raw unprocessed footnote number or other identifying label
* fn_id - the globally unique identifier for the in-body footnote link
* anchor, used to allow links from the list to the body
* ref_id - the globally unique identifier for the footnote's anchor in the
* footnote listing, used to allow links to the list from the body
*/
function gsb_theme_footnote_list($footnotes) {
$str = '<ul class="footnotes">';
// Drupal 7 requires we use "render element" which just introduces a wrapper
// around the old array.
$footnotes = $footnotes['footnotes'];
// loop through the footnotes
foreach ($footnotes as $fn) {
if(!is_array( $fn['ref_id'])) {
// Output normal footnote
$str .= '<li class="footnote" id="' . $fn['fn_id'] .'"><span class="footnote-number">' . $fn['value'] . '.</span>';
$str .= $fn['text'] . ' | <a class="footnote-link" href="#' . $fn['ref_id'] . '">' . t("Back to Text") . '</a>' . "</li>\n";
}
else {
// Output footnote that has more than one reference to it in the body.
// The only difference is to insert backlinks to all references.
// Helper: we need to enumerate a, b, c...
$abc = str_split("abcdefghijklmnopqrstuvwxyz"); $i = 0;
$str .= '<li class="footnote" id="' . $fn['fn_id'] .'"><span class="footnote-number">' . $fn['value'] . '.</span>';
foreach ($fn['ref_id'] as $ref) {
$str .= '<a class="footnote-multi" href="#' . $ref . '">' . $abc[$i] . '.</a> ';
$i++;
}
$str .= $fn['text'] . "</li>\n";
}
}
$str .= "</ul>\n";
return $str;
}
/**
* Override the file link field so that files will open in a new tab.
*/
function gsb_theme_file_link($variables) {
$file = $variables['file'];
$icon_directory = $variables['icon_directory'];
$url = file_create_url($file->uri);
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
// Set options as per anchor format described at
// http://microformats.org/wiki/file-format-examples
$options = array(
'attributes' => array(
'type' => $file->filemime . '; length=' . $file->filesize,
'target' => '_blank',
),
);
// Use the description as the link text if available.
if (empty($file->description)) {
$link_text = $file->filename;
}
else {
$link_text = $file->description;
$options['attributes']['title'] = check_plain($file->filename);
}
return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}
/**
* Implements hook_preprocess_block().
*/
function gsb_theme_preprocess_block(&$variables) {
global $theme_info;
// Add css stylesheets based on the following settings in gsb_theme.info:
// ; GSB Styles
// gsb_styles[block][1234][] = myblock.css
if (!empty($theme_info->info['gsb_styles']['block'])) {
$path = drupal_get_path('theme', $theme_info->name);
foreach($theme_info->info['gsb_styles']['block'] as $delta => $stylesheets) {
if (!empty($variables['block']) && ($variables['block']->delta == $delta || $variables['block']->module == $delta)) {
if ($variables['block']->module == $delta) {
if (!in_array($variables['block']->delta, array_keys($stylesheets))) {
continue;
}
}
foreach($stylesheets as $sheet) {
drupal_add_css($path . '/' . $sheet);
}
}
}
}
}
/**
* Implements hook_block_list_alter().
*
* Removes the 'Section Menu: Alumni' menu block
* from the alumni/help or alumni/help/* pages
*/
function gsb_theme_block_list_alter(&$blocks) {
$alias = drupal_get_path_alias(current_path());
$pos = strpos($alias, 'alumni/help');
// Check if we on the alumni/help page or an alumni/help/* subpage
if ($pos !== false && $pos == 0) {
foreach($blocks as $key => $value) {
if ($value->delta == 'section-13071') {
// remove the menu block
unset($blocks[$value->bid]);
}
}
}
}
/**
* Implements hook_field_group_pre_render_alter().
*
* Adding group wrapper css classes for all field groups
* Also, adds 'hide_this' class if element is a 'related' group wrapper and has no children
*/
function gsb_theme_field_group_pre_render_alter(&$element, $group, & $form) {
// Adding group wrapper css classes for all field groups
$group_children = array(
'group_wrapper_related' => array(
'field_related_faculty'
),
'group_wrapper_faculty' => array(
'field_faculty_1',
'field_faculty_2',
'field_faculty_directors',
'field_guest_speakers_advisors_fc'
)
);
$group_class = str_replace('_', '-', $group->group_name);
if (!empty($element['#attributes']['class']) && !in_array($group_class, $element['#attributes']['class'])) {
$element['#attributes']['class'][] = $group_class;
}
else {
$element['#attributes'] = array('class' => array($group_class));
}
// Add 'hide_this' class if group wrapper is in $group_children and has no children
if (in_array($group->group_name, array_keys($group_children))) {
$found_child = false;
foreach ($group->children as $child) {
if (!empty($element[$child]['#field_type']) && $element[$child]['#field_type'] == 'ds') {
continue;
}
if (in_array($child, $group_children[$group->group_name])) {
$first_item = $element[$child]['#items'][0]['value'];
$first_entity = $element[$child][0]['entity']['field_collection_item'][$first_item]['#entity'];
if (!empty($first_entity->field_person_fac_single_ref)) {
$found_child = TRUE;
break;
}
}
else if (!empty($element[$child]) && $element[$child] != NULL) {
$found_child = TRUE;
break;
}
}
if (!$found_child) {
if (!empty($element['#attributes']['class'])) {
$element['#attributes']['class'][] = 'hide_this';
}
else {
$element['#attributes'] = array('class' => array('hide_this'));
}
}
}
}
/**
* Implements hook_js_alter()
*/
function gsb_theme_js_alter(&$javascript) {
// Collect the scripts we want in to remain in the header scope.
$header_scripts = array();
// Change the default scope of all other scripts to footer.
// We assume if the script is scoped to header it was done so by default.
foreach ($javascript as $key => &$script) {
if ($script['scope'] == 'header' && !in_array($script['data'], $header_scripts)) {
// move all js to the footer... except modernizr
//if (!strpos($key, 'modernizr')) {
//$script['scope'] = 'footer';
//}
}
}
}