forked from backdrop/backdrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.module
2310 lines (2104 loc) · 74.2 KB
/
layout.module
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
* The Layout module creates pages and wraps existing pages in layouts.
*
* Backdrop's primary tool for positioning content is through layouts and
* blocks. A "layout" is the template that defines regions in which pieces of
* content may be placed. Each piece of content in this case is called a
* "block". Blocks may be placed multiple times in a single layout, and each
* block maintains separate settings. Each layout created saves to a
* configuration file, including all the settings for the blocks contained
* within it.
*
* Layout module provides two distinct ways of rendering pages. It is capable of
* creating a stand-alone page that is created at any custom path specified by
* the user, and it can also "wrap" the content of any path provided by a
* module. In the case where a custom path is created, Layout module registers
* the path in the menu system through hook_menu(). For wrapping module-provided
* pages, Layout module declares itself as the system-wide "route handler", as
* checked in menu_execute_active_handler(). Layout module then becomes
* responsible for calling the module-provided content as a block, and positions
* other blocks around the existing content.
*/
/**
* Layouts constant for user-defined layouts.
*/
define('LAYOUT_STORAGE_NORMAL', 1);
/**
* Layout constant for layouts that override module-defined presets.
*/
define('LAYOUT_STORAGE_OVERRIDE', 2);
/**
* Layout constant for module-defined layouts.
*/
define('LAYOUT_STORAGE_DEFAULT', 4);
/**
* Layout constant indicating the title of the layout is the default.
*/
define('LAYOUT_TITLE_DEFAULT', 'default');
/**
* Layout constant indicating the title of the layout is not shown.
*/
define('LAYOUT_TITLE_NONE', 'none');
/**
* Layout constant indicating the title of the layout is manually specified.
*/
define('LAYOUT_TITLE_CUSTOM', 'custom');
/**
* Layout constant indicating the title of the layout comes from a block.
*/
define('LAYOUT_TITLE_BLOCK', 'block');
/**
* Implements hook_menu().
*/
function layout_menu() {
$items = array();
$base = array(
'access arguments' => array('administer layouts'),
'theme callback' => 'ajax_base_page_theme',
);
$items['admin/structure/layouts'] = array(
'title' => 'Layouts',
'description' => 'Create new landing pages or modify the layout of existing pages on your site.',
'page callback' => 'layout_list_page',
'type' => MENU_NORMAL_ITEM,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/list'] = array(
'title' => 'List layouts',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/settings'] = array(
'title' => 'Templates',
'description' => 'Manage layout templates.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_settings_page'),
'type' => MENU_LOCAL_TASK,
'weight' => 20,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/add'] = array(
'title' => 'Add flexible layout template',
'page callback' => 'layout_flexible_template_settings_add_form',
'access arguments' => array('administer flexible templates'),
'type' => MENU_LOCAL_ACTION,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/%layout_flexible_tempstore/edit'] = array(
'title' => 'Configure flexible layout template',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_flexible_template_settings_edit_form', 5),
'access arguments' => array('administer flexible templates'),
'type' => MENU_NORMAL_ITEM,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/%layout_flexible_tempstore/configure'] = array(
'title' => 'Configure flexible layout template',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_flexible_template_configure_form', 5),
'access arguments' => array('administer flexible templates'),
'type' => MENU_NORMAL_ITEM,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/%layout_flexible_tempstore/delete'] = array(
'title' => 'Delete flexible layout template',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_flexible_template_delete_form', 5),
'access arguments' => array('administer flexible templates'),
'type' => MENU_NORMAL_ITEM,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/%layout_flexible_tempstore/row/%/delete'] = array(
'title' => 'Delete row',
'page callback' => 'layout_flexible_template_delete_row',
'page arguments' => array(5,7),
'access arguments' => array('administer flexible templates'),
'type' => MENU_CALLBACK,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/%layout_flexible_tempstore/row/%/select-widths'] = array(
'title' => 'Choose region widths',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_flexible_template_region_style_select', 5, 7),
'access arguments' => array('administer flexible templates'),
'type' => MENU_CALLBACK,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/%layout_flexible_tempstore/row/%/configure'] = array(
'title' => 'Add row',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_flexible_template_edit_row_form', 5, 7),
'access arguments' => array('administer flexible templates'),
'type' => MENU_CALLBACK,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/flexible-template/%layout_flexible_tempstore/row/%/configure/%'] = array(
'title' => 'Add row',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_flexible_template_edit_row_form', 5, 7, 9),
'access arguments' => array('administer flexible templates'),
'type' => MENU_CALLBACK,
'weight' => -10,
'file' => 'layout.flexible.inc',
) + $base;
$items['admin/structure/layouts/settings/toggle/%/enable'] = array(
'title' => 'Enable layout template',
'page callback' => 'layout_template_toggle_enabled',
'page arguments' => array(5, TRUE),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/settings/toggle/%/disable'] = array(
'title' => 'Disable layout template',
'page callback' => 'layout_template_toggle_enabled',
'page arguments' => array(5, FALSE),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/reorder'] = array(
'title' => 'Reorder',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_reorder_form'),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/add'] = array(
'title' => 'Add layout',
'page callback' => 'layout_add_page',
'page arguments' => array(),
'type' => MENU_LOCAL_ACTION,
'weight' => -10,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore'] = array(
'title' => 'Manage blocks',
'title callback' => 'layout_page_title',
'title arguments' => array(4),
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_content_form', 4),
'type' => MENU_NORMAL_ITEM,
'file' => 'layout.admin.inc',
) + $base;
// @deprecated: Remove backwards-compatibility redirect in 2.0.
$items['admin/structure/layouts/manage/%layout_tempstore/edit'] = array(
'page callback' => 'backdrop_goto_deprecated',
'page arguments' => array('admin/structure/layouts/manage/%layout_tempstore/blocks'),
'access arguments' => array('administer layouts'),
'type' => MENU_CALLBACK,
);
$items['admin/structure/layouts/manage/%layout_tempstore/blocks'] = array(
'title' => 'Manage blocks',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
'file' => 'layout.admin.inc',
) + $base;
// @deprecated: Remove backwards-compatibility redirect in 2.0.
$items['admin/structure/layouts/manage/%layout_tempstore/settings'] = array(
'page callback' => 'backdrop_goto_deprecated',
'page arguments' => array('admin/structure/layouts/manage/%layout_tempstore/configure'),
'access arguments' => array('administer layouts'),
'type' => MENU_CALLBACK,
);
$items['admin/structure/layouts/manage/%layout_tempstore/configure'] = array(
'title' => 'Configure layout',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_settings_form', 4),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/add-block/%/%'] = array(
'title' => 'Add block',
'page callback' => 'layout_block_add_page',
'page arguments' => array(4, 6, 7),
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/configure-region/%/%'] = array(
'title' => 'Configure region',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_configure_region_page', 4, 6, 7),
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/edit-title/editor/title'] = array(
'title' => 'Configure page title',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_title_settings_form', 4),
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/configure-block/%/%layout_tempstore_block'] = array(
'title' => 'Configure block',
'load arguments' => array(4),
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_block_configure_form', 4, 7, 6),
'file' => 'layout.admin.inc',
) + $base;
// This shortcut path does not use layout_tempstore, for efficiency when
// checking access to this path from contextual links. To work as a contextual
// link, we have to specify the context and also set the type to be a
// MENU_LOCAL_TASK, even though this page never shows up as a tab anywhere.
$items['admin/structure/layouts/manage/%layout/configure-redirect/%'] = array(
'title' => 'Configure block',
'load arguments' => array(4),
'page callback' => 'layout_block_configure_redirect',
'page arguments' => array(4, 6),
'context' => MENU_CONTEXT_INLINE,
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/remove-block/%/%layout_tempstore_block'] = array(
'title' => 'Remove block',
'load arguments' => array(4),
'page callback' => 'layout_block_remove_page',
'page arguments' => array(4, 7, 6),
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/clone'] = array(
'title' => 'Clone layout',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_clone_form', 4),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/enable'] = array(
'page callback' => 'layout_toggle_enabled',
'page arguments' => array(4, TRUE),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/disable'] = array(
'page callback' => 'layout_toggle_enabled',
'page arguments' => array(4, FALSE),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/delete'] = array(
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_delete_form', 4),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/break-lock'] = array(
'page callback' => 'layout_break_lock_page',
'page arguments' => array(4, 'layout'),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/context/add'] = array(
'title' => 'Add context',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_context_add_form', 4),
'type' => MENU_CALLBACK,
'file' => 'layout.context.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/context/edit/layout/%'] = array(
'title' => 'Configure context',
'load arguments' => array(4),
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_context_add_form', 4, 8),
'type' => MENU_CALLBACK,
'file' => 'layout.context.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/condition/add'] = array(
'title' => 'Add visibility condition',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_condition_add_form', 4),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/condition/edit/layout/%'] = array(
'title' => 'Configure condition',
'load arguments' => array(4),
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_condition_add_form', 4, NULL, NULL, 8),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/condition/add/%layout_tempstore_block'] = array(
'title' => 'Add visibility condition',
'load arguments' => array(4),
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_condition_add_form', 4, 7),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/manage/%layout_tempstore/condition/edit/%layout_tempstore_block/%'] = array(
'title' => 'Configure condition',
'load arguments' => array(4),
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_condition_add_form', 4, 7, NULL, 8),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/menu/%layout_tempstore_menu_item'] = array(
'title' => 'Menu settings',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_menu_item_form', 4),
'type' => MENU_NORMAL_ITEM,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/menu/%layout_tempstore_menu_item/settings'] = array(
'title' => 'Menu settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/menu/%layout_tempstore_menu_item/break-lock'] = array(
'page callback' => 'layout_break_lock_page',
'page arguments' => array(4, 'menu_item'),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/menu/%layout_tempstore_menu_item/condition/add'] = array(
'title' => 'Add visibility condition',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_condition_add_form', NULL, NULL, 4),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
$items['admin/structure/layouts/menu/%layout_tempstore_menu_item/condition/edit/%'] = array(
'title' => 'Configure condition',
'page callback' => 'backdrop_get_form',
'page arguments' => array('layout_condition_add_form', NULL, NULL, 4, 7),
'type' => MENU_CALLBACK,
'file' => 'layout.admin.inc',
) + $base;
// Add menu entries for each custom layout path.
foreach (layout_menu_item_load_all() as $menu_item) {
if (!empty($menu_item->disabled)) {
continue;
}
$path = array();
$page_arguments = array($menu_item->name);
$access_arguments = array($menu_item->name);
$load_arguments = array($menu_item->name, '%map', '%index');
// Replace placeholders with named placeholders for known contexts.
foreach (explode('/', $menu_item->path) as $position => $bit) {
$placeholder = $bit;
if (strpos($bit, '%') === 0) {
$placeholder = '%layout_path';
}
$path[] = $placeholder;
$page_arguments[] = $position;
$access_arguments[] = $position;
}
$menu_path = implode('/', $path);
$items[$menu_path] = layout_page_menu_item($menu_item->menu, $access_arguments, $page_arguments, $load_arguments);
// Add a parent menu item if one is configured.
if (isset($menu_item->menu['type']) && $menu_item->menu['type'] == 'default tab') {
array_pop($path);
$parent_path = implode('/', $path);
$items[$parent_path] = layout_page_menu_item($menu_item->menu['parent'], $access_arguments, $page_arguments, $load_arguments);
}
}
// A page in the Reports section to list all blocks and their modules.
$items['admin/reports/blocks'] = array(
'title' => 'Blocks',
'description' => 'Overview of all blocks and their modules.',
'page callback' => 'layout_block_list',
'access callback' => 'user_access',
'access arguments' => array('administer layouts'),
'file' => 'layout.admin.inc',
);
return $items;
}
/**
* Menu loader callback; Convert %layout_path placeholders to loaded objects.
*/
function layout_path_load($arg_value, $menu_item_name, $path_parts, $arg_position) {
$menu_item = layout_menu_item_load($menu_item_name);
$contexts = $menu_item->getContexts();
$context_info = layout_get_context_info($contexts[$arg_position]->plugin);
if (isset($context_info['load callback']) && function_exists($context_info['load callback'])) {
return call_user_func_array($context_info['load callback'], array($arg_value));
}
// Pass-through the string argument if no load callback specified.
return $arg_value;
}
/**
* Create a menu item for Layout-provided pages.
*
* @param array $menu
* The configuration for this menu item as configured by the user.
* @param $access_arguments
* The arguments for the menu system.
* @param $page_arguments
* The page callback arguments for the menu system.
* @param $load_arguments
* The magic loader arguments for the menu system.
*
* @return array
* The menu item array.
*/
function layout_page_menu_item(array $menu, array $access_arguments, array $page_arguments, array $load_arguments) {
$item = array(
'access callback' => 'layout_page_access',
'access arguments' => $access_arguments,
'page callback' => 'layout_page_callback',
'page arguments' => $page_arguments,
'load arguments' => $load_arguments,
'file' => 'layout.pages.inc',
);
if (isset($menu['title'])) {
$item['title'] = $menu['title'];
}
if (isset($menu['weight'])) {
$item['weight'] = $menu['weight'];
}
if (empty($menu['type'])) {
$menu['type'] = 'none';
}
switch ($menu['type']) {
case 'normal':
$item['type'] = MENU_NORMAL_ITEM;
// Insert item into the proper menu
$item['menu_name'] = $menu['name'];
break;
case 'tab':
$item['type'] = MENU_LOCAL_TASK;
break;
case 'action':
$item['type'] = MENU_LOCAL_ACTION;
break;
case 'default tab':
$item['type'] = MENU_DEFAULT_LOCAL_TASK;
break;
case 'none':
default:
$item['type'] = MENU_CALLBACK;
break;
}
return $item;
}
/**
* Menu title callback; Return the title for editing a layout.
*/
function layout_page_title(Layout $layout) {
// Page titles are run through check_plain() before output, so no escaping
// here is intentional. See backdrop_get_title().
return $layout->title;
}
/**
* Menu access callback; Check access for any Layout-provided page.
*/
function layout_page_access() {
module_load_include('inc', 'layout', 'layout.pages');
$args = func_get_args();
return call_user_func_array('_layout_page_access', $args);
}
/**
* Route handler callback; Execute the current route item or wrap in a layout.
*
* @param $router_item
* The menu router item for the page currently being loaded.
* @return
* The fully built HTML content for this page, which will be wrapped in
* page.tpl.php.
*
* @ingroup callbacks
*/
function layout_route_handler($router_item) {
// If a different delivery callback is specified, we're probably not returning
// HTML and it definitely should not be wrapped in a layout. Call the default
// route handler and return its response directly.
if (!backdrop_is_html() || !empty($router_item['delivery_callback']) || $router_item['page_callback'] === 'layout_page_callback') {
return menu_default_route_handler($router_item);
}
$selected_layout = layout_get_layout_by_path(NULL, $router_item);
// Safety check that we don't show an admin layout to a user who cannot view
// the admin theme. This may happen because the cached layout list does not
// include a permissions check on the admin theme.
if ($selected_layout->name === 'admin_default' && !user_access('view the administration theme')) {
$selected_layout = layout_load('default');
}
// Special handling for 404 and 403 pages to render in admin theme. The
// current path will be the 404/403 system path, and we need to check the
// original path, which is stored in "destination" by
// backdrop_deliver_html_page().
if (in_array(backdrop_get_http_header('Status'), array('404 Not Found', '403 Forbidden')) && user_access('view the administration theme')) {
if (isset($_GET['destination']) && path_is_admin($_GET['destination'])) {
$selected_layout = layout_load('admin_default');
}
}
if ($selected_layout) {
// Render the layout.
$renderer = layout_create_renderer($selected_layout->renderer_name, $selected_layout);
if ($selected_layout->isDefault()) {
$renderer->ensurePageContentBlock();
}
return $renderer->render();
}
// Fallback code if even the expected default layout cannot be found.
return menu_default_route_handler($router_item);
}
/**
* Implements hook_theme()
*/
function layout_theme() {
$base = array(
'file' => 'layout.theme.inc',
);
$items = array(
'layout' => array(
'variables' => array('content' => NULL, 'settings' => NULL, 'layout' => NULL, 'layout_info' => NULL, 'renderer' => NULL, 'attributes' => array(), 'admin' => FALSE),
'template' => 'templates/layout',
) + $base,
'layout_reorder_layouts' => array(
'render element' => 'element',
) + $base,
'layout_content_form' => array(
'template' => 'templates/layout-content-form',
'render element' => 'form',
) + $base,
'layout_info' => array(
'variables' => array('layout' => NULL),
) + $base,
'layout_condition_info' => array(
'variables' => array('layout' => NULL),
) + $base,
'layout_template_option' => array(
'variables' => array('template_info' => NULL),
) + $base,
'layout_template_info' => array(
'variables' => array('template_info' => NULL),
) + $base,
'layout_flexible_template_style_option' => array(
'variables' => array('row_style' => NULL),
) + $base,
'layout_menu_item_arguments_table' => array(
'render element' => 'element',
) + $base,
'layout_settings_context_table' => array(
'render element' => 'element',
) + $base,
'layout_conditions' => array(
'render element' => 'element',
) + $base,
'layout_region_inner' => array(
'variables' => array('blocks' => array(), 'tag' => '', 'classes' => array(), 'attributes' => array()),
) + $base,
);
// Register all layout templates.
$layout_templates = layout_get_layout_template_info();
foreach ($layout_templates as $template) {
if (!empty($template['template'])) {
$theme_key = str_replace('-', '_', $template['template']);
$items[$theme_key] = array(
'variables' => array('content' => NULL, 'settings' => NULL, 'layout' => NULL, 'layout_info' => NULL, 'renderer' => NULL, 'attributes' => array(), 'admin' => FALSE),
'template' => $template['template'],
'path' => $template['path'],
'base hook' => 'layout',
);
if (isset($template['file'])) {
$items[$theme_key]['file'] = $template['file'];
}
}
}
// Register all styles.
$styles = _layout_get_all_info('layout_style');
foreach ($styles as $style) {
if (!empty($style['block theme'])) {
$items[$style['block theme']] = array(
'variables' => array('content' => NULL, 'layout' => NULL, 'block' => NULL, 'style' => NULL, 'settings' => array(), 'attributes' => array()),
);
if (isset($style['file'])) {
$items[$style['block theme']]['file'] = $style['file'];
}
if (isset($style['path'])) {
$items[$style['block theme']]['path'] = $style['path'];
}
if (isset($style['template'])) {
$items[$style['block theme']]['template'] = $style['template'];
}
}
if (!empty($style['hook theme'])) {
if (is_array($style['hook theme'])) {
$items += $style['hook theme'];
}
elseif (function_exists($style['hook theme'])) {
$style['hook theme']($items, $style);
}
}
}
return $items;
}
/**
* Implements hook_permission().
*/
function layout_permission() {
return array(
'administer layouts' => array(
'title' => t('Administer Layouts'),
'description' => t('Add and modify layouts on pages.'),
'restrict access' => TRUE,
),
'administer flexible templates' => array(
'title' => t('Administer Flexible Templates'),
'description' => t('Create, configure and delete flexible layout templates.'),
'restrict access' => TRUE,
),
);
}
/**
* Implements hook_config_info().
*/
function layout_config_info() {
$prefixes['layout.settings'] = array(
'label' => t('Layout settings'),
'group' => t('Configuration'),
);
$prefixes['layout.layout'] = array(
'name_key' => 'name',
'label_key' => 'title',
'group' => t('Layouts'),
);
$prefixes['layout.menu_item'] = array(
'name_key' => 'name',
'label_key' => 'path',
'group' => t('Layout menu items'),
);
$prefixes['layout.flexible'] = array(
'name_key' => 'name',
'label_key' => 'title',
'group' => t('Flexible layout templates'),
);
return $prefixes;
}
/**
* Implements hook_library_info().
*/
function layout_library_info() {
$path = backdrop_get_path('module', 'layout');
$libraries['bootstrap4-gs'] = array(
'title' => 'Bootstrap4 Grid System',
'website' => 'http://v4-alpha.getbootstrap.com/layout/grid/',
'version' => BACKDROP_VERSION,
'css' => array(
$path . '/css/grid-flexbox.css' => array(),
),
'js' => array(
$path . '/js/grid-fallback.js' => array(),
),
);
return $libraries;
}
/**
* Implements hook_layout_api().
*/
function layout_layout_api() {
return array(
'file' => 'includes/layout.layout.inc',
);
}
/**
* Implements hook_block_info().
*/
function layout_block_info() {
$blocks = array();
$blocks['custom_block'] = array(
'info' => t('Custom block'),
'description' => t('A basic block for adding custom text.'),
'class' => 'BlockText',
);
$blocks['hero'] = array(
'info' => t('Hero block'),
'description' => t('A hero block often consists of text over a background image, though either are optional.'),
'class' => 'BlockHero',
);
return $blocks;
}
/**
* Implements hook_autoload_info().
*/
function layout_autoload_info() {
return array(
'LayoutHandler' => 'includes/layout_handler.class.inc',
'LayoutHandlerBroken' => 'includes/layout_handler.class.inc',
'Layout' => 'includes/layout.class.inc',
'LayoutFlexibleTemplate' => 'includes/layout_flexible.class.inc',
'Block' => 'includes/block.class.inc',
'BlockBroken' => 'includes/block.class.inc',
'BlockLegacy' => 'includes/block_legacy.class.inc',
'BlockText' => 'includes/block.text.inc',
'BlockHero' => 'includes/block.hero.inc',
'LayoutMenuItem' => 'includes/layout_menu_item.class.inc',
// Exceptions.
'LayoutException' => 'includes/layout.exceptions.inc',
'LayoutSaveException' => 'includes/layout.exceptions.inc',
'LayoutMissingException' => 'includes/layout.exceptions.inc',
// Context handlers.
'LayoutContext' => 'plugins/context/layout_context.inc',
'LayoutContextBroken' => 'plugins/context/layout_context.inc',
'LayoutOverridesPathContext' => 'plugins/context/layout_context.inc',
'LayoutStringContext' => 'plugins/context/layout_context.inc',
'EntityLayoutContext' => 'plugins/context/entity_layout_context_handler.inc',
// Access handlers.
'EntityBundleLayoutAccess' => 'plugins/access/entity_bundle_layout_access.inc',
'LayoutAccess' => 'plugins/access/layout_access.inc',
'LayoutAccessBroken' => 'plugins/access/layout_access.inc',
'LayoutAccessNegatable' => 'plugins/access/layout_access.inc',
'LanguageLayoutAccess' => 'plugins/access/language_layout_access.inc',
'FrontLayoutAccess' => 'plugins/access/front_layout_access.inc',
'EntityIDLayoutAccess' => 'plugins/access/entity_id_layout_access.inc',
'PathLayoutAccess' => 'plugins/access/path_layout_access.inc',
'UserRoleLayoutAccess' => 'plugins/access/user_role_layout_access.inc',
'UserPermissionLayoutAccess' => 'plugins/access/user_permission_layout_access.inc',
// Renderer handlers.
'LayoutRendererEditor' => 'plugins/renderers/layout_renderer_editor.inc',
'LayoutRendererFlexible' => 'plugins/renderers/layout_renderer_flexible.inc',
'LayoutRendererStandard' => 'plugins/renderers/layout_renderer_standard.inc',
// Styles.
'LayoutStyle' => 'plugins/styles/layout_style_default.inc',
'LayoutStyleDynamic' => 'plugins/styles/layout_style_dynamic.inc',
);
}
/**
* Implements hook_contextual_links_view_alter()
*/
function layout_contextual_links_view_alter(&$element, $items) {
// Convert the link to manage blocks to use a shortened URL that lands the
// user on the overall layout edit screen with a modal opened, instead of the
// path to the block edit page itself.
$links = &$element['#links'];
if (isset($links['layout-configure-redirect-'])) {
if ($position = strpos($links['layout-configure-redirect-']['href'], '/configure-redirect')) {
$last_slash = strrpos($links['layout-configure-redirect-']['href'], '/');
$uuid = substr($links['layout-configure-redirect-']['href'], $last_slash + 1);
$links['layout-configure-redirect-']['fragment'] = 'configure-block:' . $uuid;
}
}
}
/**
* Load an individual layout.
* @param string $layout_name
* The layout machine name to load.
* @param bool $skip_menu_items
* Flag to skip the attempted loading of menu items for the loaded layouts.
* This should be set to TRUE if loading layouts that definitely do not have
* menu items associated with them, for example the default layouts or a
* layout that overrides an existing menu path.
*
* @return Layout|boolean
*/
function layout_load($layout_name, $skip_menu_items = NULL) {
// Skip menu item loading for default layouts, as we know they do not have
// an associated menu item.
if (is_null($skip_menu_items)) {
$skip_menu_items = in_array($layout_name, array('default', 'admin_default'));
}
$layouts = layout_load_multiple(array($layout_name), $skip_menu_items);
return $layouts[$layout_name];
}
/**
* Load multiple layouts based on a particular criteria.
*
* @param array $layout_names
* The names of the layouts to be loaded.
* @param bool $skip_menu_items
* Flag to skip the attempted loading of menu items for the loaded layouts.
* This should be set to TRUE if loading layouts that definitely do not have
* menu items associated with them, for example the default layouts or a
* layout that overrides an existing menu path.
*
* @return Layout[]
* An array of Layout object instances.
*/
function layout_load_multiple($layout_names, $skip_menu_items = FALSE) {
$loaded_layouts = &backdrop_static(__FUNCTION__, array());
$layouts_to_load = array();
foreach ($layout_names as $layout_name) {
if (!isset($loaded_layouts[$layout_name])) {
$layouts_to_load[] = $layout_name;
}
}
if ($layouts_to_load) {
$menu_items = layout_menu_item_load_multiple($layout_names);
// Cache the raw config files once read.
$configs = layout_get_all_configs('layout');
// Create the layout instances and associate the menu items with each.
foreach ($layouts_to_load as $layout_name) {
if (isset($configs[$layout_name])) {
$layout_data = $configs[$layout_name];
$loaded_layouts[$layout_name] = new Layout($layout_data);
// Associate the applicable menu item.
if (isset($layout_data['path']) && !$skip_menu_items) {
// Most of the time, layouts will be loaded as a group, including the
// layout that owns the menu item.
if (isset($menu_items[$layout_data['path']])) {
$loaded_layouts[$layout_name]->menu_item = $menu_items[$layout_data['path']];
}
// In the situation that a layout is loaded separately of its menu
// item owner, load the menu item by path.
elseif ($menu_item = layout_menu_item_load_multiple_by_path($layout_data['path'])) {
$loaded_layouts[$layout_name]->menu_item = $menu_item;
}
}
}
}
}
// Return the requested layouts.
$layouts = array();
foreach ($layout_names as $layout_name) {
if (isset($loaded_layouts[$layout_name])) {
$layouts[$layout_name] = $loaded_layouts[$layout_name];
}
else {
$layouts[$layout_name] = FALSE;
}
}
return $layouts;
}
/**
* Load all layouts at a given path.
*
* @param string $path
* The menu routing path, with all wildcards represented by "%" symbols.
*
* @return Layout[]
* An array of load Layout object instances.
*/
function layout_load_multiple_by_path($path, $skip_menu_items = NULL) {
if ($cache = cache('layout_path')->get($path)) {
$layouts = $cache->data;
// Populate these cached layouts into layout_load_multiple() to optimize
// any future calls to it.
$static_cache = &backdrop_static('layout_load_multiple', array());
$static_cache = array_merge($layouts, $static_cache);
}
else {
$layout_names = layout_get_path_layout_names($path);
if (empty($layout_names)) {
// Skip loading menu items for the default layouts.
if (is_null($skip_menu_items)) {
$skip_menu_items = TRUE;
}
if (path_is_admin($path)) {
$layout_names[] = 'admin_default';
}
else {
$layout_names[] = 'default';
}
}
$layouts = layout_load_multiple($layout_names, $skip_menu_items);
cache('layout_path')->set($path, $layouts);
}
return $layouts;
}