-
Notifications
You must be signed in to change notification settings - Fork 10
/
template.php
1374 lines (1167 loc) · 43 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
/**
* Implements hook_theme().
*/
function cambridge_theme_theme($existing, $type, $theme, $path) {
return array(
'cambridge_theme_unstyled_list' => array(
'function' => 'cambridge_theme_unstyled_list',
'render element' => 'tree',
),
'cambridge_theme_horizontal_navigation' => array(
'function' => 'cambridge_theme_horizontal_navigation',
'render element' => 'tree',
),
'cambridge_theme_local_dropdown_menu' => array(
'function' => 'cambridge_theme_local_dropdown_menu',
'render element' => 'tree',
),
'cambridge_theme_left_navigation_structure' => array(
'function' => 'cambridge_theme_left_navigation_structure',
'render element' => 'element',
),
'cambridge_theme_left_navigation_splitter' => array(
'function' => 'cambridge_theme_left_navigation_splitter',
'render element' => 'element',
),
'cambridge_theme_left_navigation_breadcrumb' => array(
'function' => 'cambridge_theme_left_navigation_breadcrumb',
'render element' => 'element',
),
'cambridge_theme_left_navigation_navigation' => array(
'function' => 'cambridge_theme_left_navigation_navigation',
'render element' => 'element',
),
'cambridge_theme_left_navigation_children' => array(
'function' => 'cambridge_theme_left_navigation_children',
'render element' => 'element',
),
'cambridge_theme_menu_link__left_navigation_breadcrumb' => array(
'function' => 'cambridge_theme_menu_link__left_navigation_breadcrumb',
'render element' => 'element',
),
'cambridge_easy_breadcrumb' => array(
'variables' => array(
'breadcrumb' => NULL,
'segments_quantity' => NULL,
'separator' => NULL,
),
'template' => 'easy-breadcrumb',
'path' => drupal_get_path('theme', 'cambridge_theme') . '/templates',
),
);
}
/**
* Implements template_preprocess_maintenance_page().
*/
function cambridge_theme_preprocess_maintenance_page(&$variables) {
drupal_add_css(path_to_theme() . '/css/maintenance.css', array('group' => CSS_THEME, 'preprocess' => FALSE));
}
/**
* Implements template_preprocess_html().
*/
function cambridge_theme_preprocess_html(&$variables) {
$variables['classes_array'][] = 'campl-theme-' . theme_get_setting('colour_scheme');
drupal_add_html_head(
array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge',
),
'#weight' => -999, // Immediately after Content-Type.
),
'x_ua_compatible'
);
if (FALSE === module_exists('touch_icons')) {
drupal_add_html_head_link(
array(
'rel' => 'apple-touch-icon',
'href' => file_create_url(drupal_get_path('theme', 'cambridge_theme') . '/apple-touch-icon.png'),
'type' => 'image/png',
)
);
}
}
/**
* Implements theme_menu_local_tasks().
*/
function cambridge_theme_menu_local_tasks(&$variables) {
if (empty($variables['primary']) && empty($variables['secondary'])) {
return NULL;
}
$output = '<div class="campl-content-container campl-no-bottom-padding">';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
$variables['primary']['#prefix'] .= '<ul class="campl-nav campl-nav-tabs campl-unstyled-list">';
$variables['primary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['primary']);
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
$variables['secondary']['#prefix'] .= '<ul class="campl-nav campl-nav-tabs campl-unstyled-list">';
$variables['secondary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['secondary']);
}
$output .= '</div>';
return $output;
}
/**
* Implements theme_table().
*/
function cambridge_theme_table($variables) {
$variables['attributes']['class'][] = 'campl-table campl-table-bordered campl-table-striped campl-vertical-stacking-table';
return theme_table($variables);
}
/**
* Implements hook_js_alter().
*/
function cambridge_theme_js_alter(&$javascript) {
// If jquery update is not enabled, use the jQuery version provided with the house style.
if (FALSE === module_exists('jquery_update')) {
$javascript['misc/jquery.js']['data'] = drupal_get_path('theme', 'cambridge_theme') . '/js/libs/jquery-min.js';
$javascript['misc/jquery.js']['version'] = '1.7.1';
}
}
/**
* Unstyled list theme wrapper.
*/
function cambridge_theme_unstyled_list($variables) {
return '<ul class="campl-unstyled-list">' . $variables['tree']['#children'] . '</ul>';
}
/**
* Horizontal navigation theme wrapper.
*/
function cambridge_theme_horizontal_navigation($variables) {
return '<div class="campl-wrap clearfix campl-local-navigation"><div class="campl-local-navigation-container"><ul class="campl-unstyled-list">' . $variables['tree']['#children'] . '</ul></div></div>';
}
/**
* Local dropdown menu theme wrapper.
*/
function cambridge_theme_local_dropdown_menu($variables) {
return '<ul class="campl-unstyled-list local-dropdown-menu">' . $variables['tree']['#children'] . '</ul>';
}
/**
* Left navigation menu block themer.
*/
function cambridge_theme_left_navigation_block($variables) {
return $variables['tree']['#children'];
}
/**
* Left navigation menu block link themer.
*/
function cambridge_theme_left_navigation_link($variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$element['#attributes']['class'][] = 'campl-selected';
$sub_menu = '<ul class="campl-unstyled-list campl-vertical-breadcrumb-children">' .
drupal_render($element['#below']) . '</ul>';
}
$list_menu = '';
if (_cambridge_theme_is_home_path($element['#href'])) {
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
$list_menu = '<li' . drupal_attributes($element['#attributes']) . ' >' . $output . $sub_menu . "</li>\n";
}
return $list_menu;
}
/**
* Implements template_preprocess_page().
*/
function cambridge_theme_preprocess_page(&$variables) {
// Get the site slogan
$slogan = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
$variables['site_slogan'] = ($slogan) ? '' : filter_xss_admin(variable_get('site_slogan', ''));
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
// Taxonomy term listing page.
if (FALSE === empty($variables['page']['content']['system_main']['term_heading']['term']['#term']->description)) {
$variables['page']['content']['system_main']['term_heading']['#prefix'] = '<div class="campl-content-container campl-no-bottom-padding">' . $variables['page']['content']['system_main']['term_heading']['#prefix'];
$variables['page']['content']['system_main']['term_heading']['#suffix'] .= '<hr></div>';
}
if (isset($variables['page']['content']['system_main']['no_content'])) {
$variables['page']['content']['system_main']['no_content']['#prefix'] = '<div class="campl-content-container campl-no-top-padding">' . $variables['page']['content']['system_main']['no_content']['#prefix'];
$variables['page']['content']['system_main']['no_content']['#suffix'] .= '</div>';
}
}
}
/**
* Implements template_preprocess_block().
*/
function cambridge_theme_preprocess_block(&$variables) {
if (
$variables['block']->region === 'content'
&&
(
// it's not normal content
($variables['block']->module !== 'system' || $variables['block']->delta !== 'main')
||
// but it can be a form
isset($variables['elements']['#form_id'])
||
// or a comment form
isset($variables['elements']['comment_form'])
||
// or a user profile
(isset($variables['elements']['#theme']) && $variables['elements']['#theme'] === 'user_profile')
||
// or a default Drupal not found message
(
isset($variables['elements']['main']['#children'])
&&
$variables['elements']['main']['#children'] == t(
'The requested page "@path" could not be found.',
array('@path' => request_uri())
)
)
||
// or a default Drupal access denied message
(
isset($variables['elements']['main']['#children'])
&&
$variables['elements']['main']['#children'] == t('You are not authorized to access this page.')
)
||
// or an empty front page
isset($variables['elements']['default_message'])
)
&&
// it's not a view block
$variables['block']->module !== 'views'
) {
$variables['classes_array'][] = 'campl-content-container';
}
elseif ($variables['block']->region === 'sidebar' && $variables['block']->module !== 'views') {
$variables['content_attributes_array']['class'][] = 'campl-content-container';
}
elseif ($variables['block']->region === 'partnerships') {
$variables['classes_array'][] = 'campl-content-container campl-logo-container campl-bottom-padding';
$variables['title_attributes_array']['class'][] = 'campl-branding-title';
}
elseif (in_array($variables['block']->region, array('footer_1', 'footer_2', 'footer_3', 'footer_4'))) {
$variables['classes_array'][] = 'campl-content-container campl-navigation-list';
$variables['theme_hook_suggestions'][] = 'block__footer_x';
}
}
/**
* Implements hook_form_FORM_ID_alter() for a Views exposed form.
*/
function cambridge_theme_form_views_exposed_form_alter(&$form) {
$form['#attributes']['class'][] = 'campl-content-container';
}
/**
* Implements hook_menu_block_tree_alter().
*/
function cambridge_theme_menu_block_tree_alter(&$tree, &$config) {
$block = _cambridge_theme_block_load('menu_block', $config['delta']);
// If the block is enabled by Context, the region won't currently be set.
if (BLOCK_REGION_NONE == $block->region && module_exists('context')) {
if ($plugin = context_get_plugin('reaction', 'block')) {
foreach (array('left_navigation', 'horizontal_navigation') as $region) {
$context_blocks = $plugin->block_list($region);
$key = sprintf('%s-%s', 'menu_block', $config['delta']);
if (isset($context_blocks[$key])) {
$block->region = $context_blocks[$key]->region;
}
}
}
}
if ('left_navigation' === $block->region) {
// Force menu block configuration.
$config['level'] = 1;
$config['follow'] = 0;
$config['depth'] = 0;
$config['sort'] = 1;
$tree = _cambridge_theme_mark_active_item_in_tree($tree);
}
elseif ('horizontal_navigation' === $block->region) {
// Force menu block configuration.
$config['level'] = 1;
$config['follow'] = 0;
$config['depth'] = 0;
$config['sort'] = 0;
$tree = _cambridge_theme_mark_active_item_in_tree($tree);
_cambridge_theme_add_overview_items($tree);
}
}
/**
* Cycle through the tree to find a faux-active item.
*/
function _cambridge_theme_mark_active_item_in_tree($tree) {
foreach ($tree as $key => $item) {
$tree[$key] = _cambridge_theme_mark_active_item($item);
}
return $tree;
}
/**
* Add faux overview items in menu tree to allow clicking in mobile view
*/
function _cambridge_theme_add_overview_items(&$tree) {
foreach ($tree as $key => &$value) {
// Ignore disabled menu items
if($value['link']['hidden'] == 0) {
// Ignore childless items
if($value['link']['has_children'] == 1) {
// now recursively check any children
_cambridge_theme_add_overview_items($tree[$key]['below']);
// add the overview except for firstchild items
if ('<firstchild>' !== $value['link']['link_path']) {
// create and overview page with same link data but nothing below
$overview = array('link' => $value['link'], 'below' => array());
//dpm('needs an overview page', $overview['link']['title']);
$overview['link']['title'] .= ' overview'; // append overview
// pre-pend it to existing tree
$temp = $value['below'];
$temp = array('overview' => $overview) + $temp;
$tree[$key]['below'] = $temp;
}
}
}
}
}
/**
* Mark the end of active trails as faux active.
*/
function _cambridge_theme_mark_active_item($item) {
if (TRUE == $item['link']['in_active_trail'] && 0 === count($item['below']) && $_GET['q'] != $item['link']['href']) {
$item['link']['cambridge_theme_faux_active'] = TRUE;
}
foreach ($item['below'] as $key => $child) {
$item['below'][$key] = _cambridge_theme_mark_active_item($child);
}
return $item;
}
/**
* Implements theme_status_messages().
*/
function cambridge_theme_status_messages($variables) {
$display = $variables['display'];
$output = '';
foreach (drupal_get_messages($display) as $type => $messages) {
switch ($type) {
case 'status':
$type = 'success';
$name = t('Success');
break;
case 'error':
$type = 'warning';
$name = t('Warning');
break;
case 'warning':
$type = 'alert';
$name = t('Alert');
break;
default:
$type = 'information';
$name = t('Information');
}
foreach ($messages as $message) {
$output .= '<div class="campl-notifications-panel campl-' . $type . '-panel campl-notifications-container clearfix">';
$output .= '<div class="campl-column4">';
$output .= '<p class="campl-notifications-icon campl-' . $type . '-icon">' . $name . ':</p>';
$output .= '</div>';
$output .= '<div class="campl-column8">';
$output .= '<p>' . $message . "</p>";
$output .= "</div>";
$output .= "</div>";
}
}
return $output;
}
/**
* Implements theme_image().
*/
function cambridge_theme_image($variables) {
if (isset($variables['attributes']['class']) && FALSE === is_array($variables['attributes']['class'])) {
$variables['attributes']['class'] = array($variables['attributes']['class']);
}
// Make sure class is added to all images.
$variables['attributes']['class'][] = 'campl-scale-with-grid';
// We should always output the alt attribute even if its not set
if (!isset($variables['alt'])) {
$variables['alt'] = "";
}
return theme_image($variables);
}
/**
* Implements hook_block_view_alter().
*/
function cambridge_theme_block_view_alter(&$data, $block) {
if ($block->module === 'menu_block') {
$data['content']['#content'] = _cambridge_theme_add_active_item($data['content']['#content']);
}
if (in_array($block->region, array('footer_1', 'footer_2', 'footer_3', 'footer_4'))) {
// Add wrapper to blocks in the local footer column regions.
if (isset($data) && array_key_exists('content', $data) && is_array($data['content'])) {
if ($block->module === 'menu_block') {
$data['content']['#content']['#theme_wrappers'] = array('cambridge_theme_unstyled_list');
}
else {
$data['content']['#theme_wrappers'] = array('cambridge_theme_unstyled_list');
}
}
}
elseif ($block->module === 'menu_block' && $block->region === 'horizontal_navigation') {
// Forcibly disable the block title.
$data['subject'] = NULL;
$block->title = NULL;
// Add wrappers to the horizontal navigation regions.
$data['content']['#content']['#theme_wrappers'] = array('cambridge_theme_horizontal_navigation');
foreach ($data['content']['#content'] as $id => $item) {
if (isset($data['content']['#content'][$id]['#below']) && count($data['content']['#content'][$id]['#below'])) {
$data['content']['#content'][$id]['#below']['#theme_wrappers'] = array('cambridge_theme_local_dropdown_menu');
foreach ($data['content']['#content'][$id]['#below'] as $belowId => $below) {
if ('#' === substr($belowId, 0, 1)) {
continue;
}
if (count($data['content']['#content'][$id]['#below'][$belowId]['#below'])) {
$data['content']['#content'][$id]['#below'][$belowId]['#below']['#theme_wrappers'] = array('cambridge_theme_local_dropdown_menu');
}
}
}
}
$data['content']['#content'] = _cambridge_theme_find_active_horizontal_navigation($data['content']['#content']);
foreach ($data['content']['#content'] as $key => $item) {
if (FALSE === is_int($key)) {
continue;
}
if (in_array('active-trail', $item['#attributes']['class'])) {
$data['content']['#content'][$key]['#localized_options']['attributes']['class'][] = 'campl-selected';
}
}
}
elseif ($block->module === 'menu_block' && $block->region === 'left_navigation') {
if (FALSE === isset($data['content']['#content'])) {
return;
}
// Forcibly disable the block title.
$data['subject'] = NULL;
$block->title = NULL;
$content = $data['content']['#content'];
$active = NULL;
foreach ($content as $key => $item) {
if (FALSE === is_int($key)) {
continue;
}
if (TRUE === in_array('active', $item['#attributes']['class'])) {
$active = $content[$key];
}
}
if (NULL === $active) {
foreach ($content as $key => $item) {
if (FALSE === is_int($key)) {
continue;
}
if (TRUE === in_array('active-trail', $item['#attributes']['class'])) {
// Sometimes the menu has an active-trail without an active item (eg Feeds module's log pages. Cycle through
// the items to make sure we have one. Not ideal, but the menu would break otherwise.
$active = _cambridge_theme_left_navigation_has_active_item($content[$key]);
break;
}
}
}
$breadcrumbs = array();
if (NULL === $active) {
// No active part, so just display the menu at the top level.
$navigation = array();
$siblings = $content;
foreach ($siblings as $key => $sibling) {
if (FALSE === is_int($key)) {
continue;
}
if (_cambridge_theme_is_home_path($sibling['#href'])) {
$breadcrumbs = array($key => $siblings[$key]) + $breadcrumbs;
$breadcrumbs[$key]['#title'] = variable_get('site_name');
break;
}
}
// If there isn't a breadcrumb already (ie the top level doesn't have a 'Home' menu item), make one that points to
// the front page.
if (count($breadcrumbs) === 0) {
$breadcrumbs['foo'] = array(
'#theme' => array('menu_link'),
'#title' => variable_get('site_name'),
'#href' => '<front>',
'#attributes' => array(),
);
}
}
else {
$active['_siblings'] = $content;
$navigation = array();
// See if the top level has a 'Home' menu item, and make it the first breadcrumb level if found.
foreach ($active['_siblings'] as $key => $sibling) {
if (FALSE === is_int($key)) {
continue;
}
if (_cambridge_theme_is_home_path($sibling['#href'])) {
$breadcrumbs = array($key => $active['_siblings'][$key]) + $breadcrumbs;
$breadcrumbs[$key]['#title'] = variable_get('site_name');
break;
}
}
// If there isn't a breadcrumb already (ie the top level doesn't have a 'Home' menu item), make one that points to
// the front page.
if (count($breadcrumbs) === 0) {
$breadcrumbs['foo'] = array(
'#theme' => array('menu_link'),
'#title' => variable_get('site_name'),
'#href' => '<front>',
'#attributes' => array(),
);
}
// Break up the menu into the breadcrumb and navigation sections.
_cambridge_theme_left_navigation_break_up($active, $breadcrumbs, $navigation);
// Stop the category being a link when on the page (unless it's a faux active item).
$key = key($navigation);
if (in_array('active', $navigation[$key]['#attributes']['class'])) {
$navigation[$key]['#attributes']['class'][] = 'campl-selected';
if (FALSE === isset($navigation[$key]['#original_link']['cambridge_theme_faux_active'])) {
$navigation[$key]['#href'] = '<none>';
}
}
// We don't want to display grandchildren.
foreach ($navigation[$key]['#below'] as $childKey => $child) {
if (FALSE === is_int($childKey)) {
continue;
}
$navigation[$key]['#below'][$childKey]['#below'] = array();
if (in_array('active', $child['#attributes']['class'])) {
if (FALSE === isset($child['#original_link']['cambridge_theme_faux_active'])) {
$navigation[$key]['#below'][$childKey]['#attributes']['class'][] = 'campl-selected';
}
else {
$navigation[$key]['#below'][$childKey]['#attributes']['class'][] = 'campl-faux-selected';
}
}
}
// Pick out siblings.
$siblings = $navigation[$key]['_siblings'];
unset($siblings[$key]);
if (_cambridge_theme_is_home_path($navigation[$key]['#href'])) {
$navigation = array();
}
}
foreach ($siblings as $key => $sibling) {
if (FALSE === is_int($key)) {
continue;
}
// We don't want to display children of the siblings.
$siblings[$key]['#below'] = array();
if (_cambridge_theme_is_home_path($sibling['#href'])) {
unset($siblings[$key]);
}
}
// Construct the two menu parts.
$data['content']['#content'] = array();
$data['content']['#content']['#theme'] = array('cambridge_theme_left_navigation_structure');
$data['content']['#content']['#below']['breadcrumb']['#below'] = $breadcrumbs;
$data['content']['#content']['#below']['breadcrumb']['#below']['#theme_wrappers'] = array('cambridge_theme_left_navigation_breadcrumb');
$data['content']['#content']['#below']['breadcrumb']['#theme'] = array('cambridge_theme_left_navigation_splitter');
$data['content']['#content']['#below']['breadcrumb']['#href'] = '<front>';
$data['content']['#content']['#below']['breadcrumb']['#localized_options'] = array();
$data['content']['#content']['#below']['breadcrumb']['#attributes'] = array();
$data['content']['#content']['#below']['breadcrumb']['#bid'] = array('module' => 'menu_block', 'delta' => 2);
foreach ($data['content']['#content']['#below']['breadcrumb']['#below'] as $key => $value) {
if (FALSE === isset($data['content']['#content']['#below']['breadcrumb']['#below'][$key]['#theme'])) {
continue;
}
array_unshift(
$data['content']['#content']['#below']['breadcrumb']['#below'][$key]['#theme'],
'menu_link__left_navigation_breadcrumb'
);
}
$data['content']['#content']['#below']['navigation']['#below'] = array_merge($navigation, $siblings);
$data['content']['#content']['#below']['navigation']['#below']['#theme_wrappers'] = array('cambridge_theme_left_navigation_navigation');
$data['content']['#content']['#below']['navigation']['#theme'] = array('cambridge_theme_left_navigation_splitter');
$data['content']['#content']['#below']['navigation']['#href'] = '<front>';
$data['content']['#content']['#below']['navigation']['#localized_options'] = array();
$data['content']['#content']['#below']['navigation']['#attributes'] = array();
$data['content']['#content']['#below']['navigation']['#bid'] = array('module' => 'menu_block', 'delta' => 2);
foreach ($data['content']['#content']['#below']['navigation']['#below'] as $key => $value) {
if (FALSE === isset($data['content']['#content']['#below']['navigation']['#below'][$key]['#below']['#theme_wrappers'])) {
continue;
}
$data['content']['#content']['#below']['navigation']['#below'][$key]['#below']['#theme_wrappers'] = array(array('cambridge_theme_left_navigation_children'));
}
}
}
/**
* Cycle through a tree and make items marked as faux active as actually active.
*/
function _cambridge_theme_add_active_item($items) {
foreach ($items as $key => $item) {
if (FALSE === is_int($key)) {
continue;
}
if (
isset($item['#original_link']['cambridge_theme_faux_active'])
&&
FALSE === in_array('active', $item['#attributes']['class'])
) {
$items[$key]['#attributes']['class'][] = 'active';
}
$items[$key]['#below'] = _cambridge_theme_add_active_item($items[$key]['#below']);
}
return $items;
}
/**
* Add the campl-current-page class to the current page.
*/
function _cambridge_theme_find_active_horizontal_navigation($objects) {
foreach ($objects as $key => $object) {
if ('#' === substr($key, 0, 1)) {
continue;
}
$has_children = is_array($object['#below']) && count($object['#below']);
if (in_array('active', (array) $object['#attributes']['class'])) {
$is_active = TRUE;
// If the item is an overview/firstchild link the parent item will appear as active, so take a look at the
// children to see if there's another active item.
if (TRUE === $has_children) {
foreach ($object['#below'] as $child) {
if (isset($child['#attributes']['class']) && in_array('active', $child['#attributes']['class'])) {
$is_active = FALSE;
break;
}
}
}
if (TRUE === $is_active) {
$objects[$key]['#attributes']['class'][] = 'campl-current-page';
break;
}
}
if (TRUE === $has_children) {
$objects[$key]['#below'] = _cambridge_theme_find_active_horizontal_navigation($object['#below']);
}
}
return $objects;
}
/**
* Test whether the menu has an active item.
*/
function _cambridge_theme_left_navigation_has_active_item($item) {
if (is_array($item['#attributes']['class']) && in_array('active', $item['#attributes']['class'])) {
return $item;
}
if (is_array($item['#below'])) {
foreach ($item['#below'] as $key => $child) {
if (FALSE === is_int($key)) {
continue;
}
if (NULL !== _cambridge_theme_left_navigation_has_active_item($child)) {
return $item;
}
}
}
return NULL;
}
/**
* Break up the left-hand navigation into the breadcrumb and navigation sections.
*/
function _cambridge_theme_left_navigation_break_up(&$item, &$breadcrumbs, &$navigation) {
if (
FALSE === in_array('active-trail', $item['#attributes']['class'])
&&
FALSE === in_array('active', $item['#attributes']['class'])
) {
return;
}
$child_is_active = FALSE;
foreach ($item['#below'] as $key => $child) {
if (FALSE === is_int($key)) {
continue;
}
$item['#below'][$key]['_siblings'] = $item['#below'];
if (TRUE === in_array('active', $child['#attributes']['class'])) {
$child_is_active = count($child['#below']) === 0;
break;
}
}
if (
$child_is_active
||
(
in_array('active', $item['#attributes']['class'])
&&
$item['#original_link']['link_path'] !== '<firstchild>'
)
) {
$navigation[$item['#original_link']['mlid']] = $item;
return;
}
$breadcrumbs[$item['#original_link']['mlid']] = $item;
$breadcrumbs[$item['#original_link']['mlid']]['#below'] = array();
foreach ($item['#below'] as $key => $child) {
if (FALSE === is_int($key)) {
continue;
}
_cambridge_theme_left_navigation_break_up($child, $breadcrumbs, $navigation);
$item['#below'][$key] = $child;
}
}
/**
* Wrap the left navigation structure.
*/
function cambridge_theme_left_navigation_structure($variables) {
$output = drupal_render($variables['element']['#below']);
return '<div class="campl-tertiary-navigation-structure">' . $output . '</div>';
}
/**
* Wrap the left navigation parts.
*/
function cambridge_theme_left_navigation_splitter($variables) {
return drupal_render($variables['element']['#below']);
}
/**
* Wrap the left navigation breadcrumb.
*/
function cambridge_theme_left_navigation_breadcrumb($variables) {
return '<ul class="campl-unstyled-list campl-vertical-breadcrumb">' . $variables['element']['#children'] . '</ul>';
}
/**
* Implements theme_menu_link__left_navigation_breadcrumb().
*/
function cambridge_theme_menu_link__left_navigation_breadcrumb(array $variables) {
$element = $variables['element'];
$element['#localized_options']['html'] = TRUE;
$output = l(
$element['#title'] . '<span class="campl-vertical-breadcrumb-indicator"></span>',
$element['#href'],
$element['#localized_options']
);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . '</li>';
}
/**
* Wrap the left navigation navigation.
*/
function cambridge_theme_left_navigation_navigation($variables) {
return '<ul class="campl-unstyled-list campl-vertical-breadcrumb-navigation">' . $variables['element']['#children'] . '</ul>';
}
/**
* Wrap the left navigation navigation children.
*/
function cambridge_theme_left_navigation_children($variables) {
return '<ul class="campl-unstyled-list campl-vertical-breadcrumb-children">' . $variables['element']['#children'] . '</ul>';
}
/**
* Implements theme_menu_link().
*/
function cambridge_theme_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
if ($element['#href'] === '<none>') {
$output = $element['#title'];
}
else {
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
}
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
/**
* Implements theme_pager().
*/
function cambridge_theme_pager($variables) {
global $pager_page_array, $pager_total;
$element = $variables['element'];
$parameters = $variables['parameters'];
$pager_current_index = $pager_page_array[$element];
$pager_current_index = $pager_current_index < 0 ? 0 : $pager_current_index;
$pager_total_pages = $pager_total[$element];
$pager_max_index = $pager_total_pages - 1;
if ($pager_total_pages <= 1) {
return '';
}
$li_previous = theme(
'pager_previous',
array('text' => 'previous', 'element' => $element, 'interval' => 1, 'parameters' => $parameters)
);
$li_first = theme(
'pager_first',
array('text' => 1, 'element' => $element, 'interval' => 1, 'parameters' => $parameters)
);
$li_last = theme(
'pager_last',
array('text' => $pager_total_pages, 'element' => $element, 'interval' => 1, 'parameters' => $parameters)
);
$li_next = theme(
'pager_next',
array('text' => 'next', 'element' => $element, 'interval' => 1, 'parameters' => $parameters)
);
if ($li_previous) {
$items[] = array('class' => array('campl-previous-li'), 'data' => $li_previous,);
}
if ($li_first) {
$items[] = array('data' => $li_first);
}
if ($pager_current_index == 2 && $pager_max_index > 2) {
// On the third page, add in page 2 to prevent "1 ... 3".
$items[] = array(
'data' => theme(
'pager_link',
array(
'text' => $pager_current_index,
'page_new' => array($pager_current_index - 1),
'element' => $element,
'parameters' => $parameters,
)
)
);
}
elseif ($pager_current_index == $pager_max_index && $pager_max_index == 3) {
// On the last page of four, add page 2 to prevent "1 ... 3 4".
$items[] = array(
'data' => theme(
'pager_link',
array(
'text' => $pager_current_index - 1,
'page_new' => array($pager_current_index - 2),
'element' => $element,
'parameters' => $parameters,
)
)
);
}
elseif ($pager_current_index > 1 && $pager_max_index > 2) {
$items[] = array('data' => '<span class="campl-elipsis">…</span>');
}
if (!$li_last && $pager_current_index > 1) {
// On the last page, try and add the penultimate.
$items[] = array(
'data' => theme(
'pager_link',
array(
'text' => $pager_current_index,
'page_new' => array($pager_current_index - 1),
'element' => $element,
'parameters' => $parameters,
)
)
);
}
$items[] = array('class' => array('campl-active'), 'data' => '<span>' . ($pager_current_index + 1) . '</span>');