-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_block-2x-ctools_exportables-693302-163.ding2.patch
1220 lines (1195 loc) · 43.4 KB
/
menu_block-2x-ctools_exportables-693302-163.ding2.patch
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
diff --git a/menu_block.admin.inc b/menu_block.admin.inc
index eda4fd6..1a22f93 100644
--- a/menu_block.admin.inc
+++ b/menu_block.admin.inc
@@ -5,88 +5,19 @@
*/
/**
- * Menu callback: display the menu block addition form.
- *
- * @see menu_block_add_block_form_submit()
- */
-function menu_block_add_block_form($form, &$form_state) {
- module_load_include('inc', 'block', 'block.admin');
- $form = block_admin_configure($form, $form_state, 'menu_block', NULL);
-
- // Other modules should be able to use hook_form_block_add_block_form_alter()
- // to modify this form, so add a base form ID.
- $form_state['build_info']['base_form_id'] = 'block_add_block_form';
-
- // Prevent block_add_block_form_validate/submit() from being automatically
- // added because of the base form ID by providing these handlers manually.
- $form['#validate'] = array();
- $form['#submit'] = array('menu_block_add_block_form_submit');
-
- return $form;
-}
-
-/**
- * Save the new menu block.
- */
-function menu_block_add_block_form_submit($form, &$form_state) {
- // Determine the delta of the new block.
- $block_ids = variable_get('menu_block_ids', array());
- $delta = empty($block_ids) ? 1 : max($block_ids) + 1;
- $form_state['values']['delta'] = $delta;
-
- // Save the new array of blocks IDs.
- $block_ids[] = $delta;
- variable_set('menu_block_ids', $block_ids);
-
- // Save the block configuration.
- menu_block_block_save($delta, $form_state['values']);
-
- // Run the normal new block submission (borrowed from block_add_block_form_submit).
- $query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'region', 'status', 'weight', 'delta', 'cache'));
- foreach (list_themes() as $key => $theme) {
- if ($theme->status) {
- $region = !empty($form_state['values']['regions'][$theme->name]) ? $form_state['values']['regions'][$theme->name] : BLOCK_REGION_NONE;
- $query->values(array(
- 'visibility' => (int) $form_state['values']['visibility'],
- 'pages' => trim($form_state['values']['pages']),
- 'custom' => (int) $form_state['values']['custom'],
- 'title' => $form_state['values']['title'],
- 'module' => $form_state['values']['module'],
- 'theme' => $theme->name,
- 'region' => ($region == BLOCK_REGION_NONE ? '' : $region),
- 'status' => 0,
- 'status' => (int) ($region != BLOCK_REGION_NONE),
- 'weight' => 0,
- 'delta' => $delta,
- 'cache' => DRUPAL_NO_CACHE,
- ));
- }
- }
- $query->execute();
-
- $query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
- foreach (array_filter($form_state['values']['roles']) as $rid) {
- $query->values(array(
- 'rid' => $rid,
- 'module' => $form_state['values']['module'],
- 'delta' => $delta,
- ));
- }
- $query->execute();
-
- drupal_set_message(t('The block has been created.'));
- cache_clear_all();
- $form_state['redirect'] = 'admin/structure/block';
-}
-
-/**
* Alters the block admin form to add delete links next to menu blocks.
*/
function _menu_block_form_block_admin_display_form_alter(&$form, $form_state) {
- $exported = menu_block_get_exported_blocks();
- foreach (variable_get('menu_block_ids', array()) as $delta) {
- if (!isset($exported[$delta])) {
- $form['blocks']['menu_block_' . $delta]['delete'] = array('#type' => 'link', '#title' => t('delete'), '#href' => 'admin/structure/block/delete-menu-block/' . $delta);
+ foreach (menu_block_load_all() as $delta => $menu_block) {
+ if ('Default' !== $menu_block->type) {
+ $form['blocks']['menu_block_' . $delta]['delete'] = array(
+ '#type' => 'link',
+ '#title' => $menu_block->type == 'Overridden' ? t('revert') : t('delete'),
+ '#href' => url('admin/structure/menu_block/list/' . $delta . '/' . ($menu_block->type == 'Overridden' ? 'revert' : 'delete'), array(
+ 'absolute' => TRUE,
+ 'query' => array('destination' => ltrim(request_uri(), '/')),
+ )),
+ );
}
}
if (variable_get('menu_block_suppress_core')) {
@@ -132,11 +63,8 @@ function menu_block_delete_form_submit($form, &$form_state) {
*/
function _menu_block_block_info() {
$blocks = array();
- $deltas = variable_get('menu_block_ids', array());
- $exported = menu_block_get_exported_blocks();
- $deltas = array_unique(array_merge($deltas, array_keys($exported)));
- foreach ($deltas as $delta) {
- $blocks[$delta]['info'] = _menu_block_format_title(menu_block_get_config($delta));
+ foreach (menu_block_load_all() as $delta => $menu_block) {
+ $blocks[$delta]['info'] = check_plain($menu_block->label);
// Menu blocks can't be cached because each menu item can have
// a custom access callback. menu.inc manages its own caching.
$blocks[$delta]['cache'] = DRUPAL_NO_CACHE;
@@ -145,309 +73,34 @@ function _menu_block_block_info() {
}
/**
- * Return the title of the block.
- *
- * @param $config
- * array The configuration of the menu block.
- * @return
- * string The title of the block.
- */
-function _menu_block_format_title($config) {
- // If an administrative title is specified, use it.
- if (!empty($config['admin_title'])) {
- return check_plain($config['admin_title']);
- }
- $menus = menu_block_get_all_menus();
- $menus[MENU_TREE__CURRENT_PAGE_MENU] = t('Current menu');
- if (empty($config['menu_name'])) {
- $title = t('Unconfigured menu block');
- }
- elseif (!isset($menus[$config['menu_name']])) {
- $title = t('Deleted/missing menu @menu', array('@menu' => $config['menu_name']));
- }
- else {
- // Show the configured levels in the block info
- $replacements = array(
- '@menu_name' => $menus[$config['menu_name']],
- '@level1' => $config['level'],
- '@level2' => $config['level'] + $config['depth'] - 1,
- );
- if ($config['parent_mlid']) {
- $parent_item = menu_link_load($config['parent_mlid']);
- $replacements['@menu_name'] = $parent_item['title'];
- }
- if ($config['follow']) {
- $title = t('@menu_name (active menu item)', $replacements);
- }
- elseif ($config['depth'] == 1) {
- $title = t('@menu_name (level @level1)', $replacements);
- }
- elseif ($config['depth']) {
- if ($config['expanded']) {
- $title = t('@menu_name (expanded levels @level1-@level2)', $replacements);
- }
- else {
- $title = t('@menu_name (levels @level1-@level2)', $replacements);
- }
- }
- else {
- if ($config['expanded']) {
- $title = t('@menu_name (expanded levels @level1+)', $replacements);
- }
- else {
- $title = t('@menu_name (levels @level1+)', $replacements);
- }
- }
- }
- return $title;
-}
-
-/**
* Implements hook_block_configure().
*/
function _menu_block_block_configure($delta = '') {
- // Create a pseudo form state.
- $form_state = array('values' => menu_block_get_config($delta));
- return menu_block_configure_form(array(), $form_state);
-}
-
-/**
- * Returns the configuration form for a menu tree.
- *
- * @param $form_state
- * array An associated array of configuration options should be present in the
- * 'values' key. If none are given, default configuration is assumed.
- * @return
- * array The form in Form API format.
- */
-function menu_block_configure_form($form, &$form_state) {
- $config = array();
- // Get the config from the form state.
- if (!empty($form_state['values'])) {
- $config = $form_state['values'];
- if (!empty($config['parent'])) {
- list($config['menu_name'], $config['parent_mlid']) = explode(':', $config['parent']);
- }
- }
- // Merge in the default configuration.
- $config += menu_block_default_config();
-
- // Don't display the config form if this delta is exported to code.
- if (!empty($config['exported_to_code'])) {
- $form['exported_message'] = array(
- '#markup' => '<p><em>' . t('Configuration is being provided by code.') . '</em></p>',
- );
- return $form;
- }
-
- // Build the standard form.
- $form['#attached']['js'][] = drupal_get_path('module', 'menu_block') . '/menu-block.js';
- $form['#attached']['css'][] = drupal_get_path('module', 'menu_block') . '/menu-block.admin.css';
- $form['#attached']['library'][] = array('system', 'ui.button');
-
- $form['menu-block-wrapper-start'] = array(
- '#markup' => '<div id="menu-block-settings">',
- '#weight' => -30,
- );
- $form['display_options'] = array(
- '#type' => 'radios',
- '#title' => t('Display'),
- '#default_value' => 'basic',
- '#options' => array(
- 'basic' => t('Basic options'),
- 'advanced' => t('Advanced options'),
- ),
- '#attributes' => array('class' => array('clearfix')),
- '#weight' => -29,
- );
- $form['title_link'] = array(
- '#type' => 'checkbox',
- '#title' => t('Block title as link'),
- '#default_value' => $config['title_link'],
- '#description' => t('Make the default block title a link to that menu item. An overridden block title will not be a link.'),
- '#states' => array(
- 'visible' => array(
- ':input[name=title]' => array('value' => ''),
- ),
- ),
- );
- // We need a different state if the form is in a Panel overlay.
- if (isset($form['override_title'])) {
- $form['title_link']['#states'] = array(
- 'visible' => array(
- ':input[name=override_title]' => array('checked' => FALSE),
- ),
- );
- }
- $form['admin_title'] = array(
- '#type' => 'textfield',
- '#default_value' => $config['admin_title'],
- '#title' => t('Administrative title'),
- '#description' => t('This title will be used administratively to identify this block. If blank, the regular title will be used.'),
- );
- $menus = menu_block_get_all_menus();
- $form['menu_name'] = array(
- '#type' => 'select',
- '#title' => t('Menu'),
- '#default_value' => $config['menu_name'],
- '#options' => $menus,
- '#description' => t('The preferred menus used by <em><the menu selected by the page></em> can be customized on the <a href="!url">Menu block settings page</a>.', array('!url' => url('admin/config/user-interface/menu-block'))),
- '#attributes' => array('class' => array('menu-block-menu-name')),
- );
- $form['level'] = array(
- '#type' => 'select',
- '#title' => t('Starting level'),
- '#default_value' => $config['level'],
- '#options' => array(
- '1' => t('1st level (primary)'),
- '2' => t('2nd level (secondary)'),
- '3' => t('3rd level (tertiary)'),
- '4' => t('4th level'),
- '5' => t('5th level'),
- '6' => t('6th level'),
- '7' => t('7th level'),
- '8' => t('8th level'),
- '9' => t('9th level'),
- ),
- '#description' => t('Blocks that start with the 1st level will always be visible. Blocks that start with the 2nd level or deeper will only be visible when the trail to the active menu item passes though the block’s starting level.'),
+ ctools_include('export');
+ module_load_include('inc', 'menu_block', 'plugins/export_ui/menu_block');
+ $form = array();
+ $form_state = array(
+ 'item' => ctools_export_crud_load('menu_blocks', $delta),
+ 'menu_block' => 'block',
);
- // The value of "follow" in the database/config array is either FALSE or the
- // value of the "follow_parent" form element.
- if ($follow = $config['follow']) {
- $follow_parent = $follow;
- $follow = 1;
- }
- else {
- $follow_parent = 'active';
- }
- $form['follow'] = array(
- '#type' => 'checkbox',
- '#title' => t('Make the starting level follow the active menu item.'),
- '#default_value' => $follow,
- '#description' => t('If the active menu item is deeper than the level specified above, the starting level will follow the active menu item. Otherwise, the starting level of the tree will remain fixed.'),
- '#element_validate' => array('menu_block_configure_form_follow_validate'),
- );
- $form['follow_parent'] = array(
- '#type' => 'select',
- '#title' => t('Starting level will be'),
- '#default_value' => $follow_parent,
- '#options' => array(
- 'active' => t('Active menu item'),
- 'child' => t('Children of active menu item'),
- ),
- '#description' => t('When following the active menu item, specify if the starting level should be the active menu item or its children.'),
- '#states' => array(
- 'visible' => array(
- ':input[name=follow]' => array('checked' => TRUE),
- ),
- ),
- );
- $form['depth'] = array(
- '#type' => 'select',
- '#title' => t('Maximum depth'),
- '#default_value' => $config['depth'],
- '#options' => array(
- '1' => '1',
- '2' => '2',
- '3' => '3',
- '4' => '4',
- '5' => '5',
- '6' => '6',
- '7' => '7',
- '8' => '8',
- '9' => '9',
- '0' => t('Unlimited'),
- ),
- '#description' => t('From the starting level, specify the maximum depth of the menu tree.'),
- );
- $form['depth_relative'] = array(
- '#type' => 'checkbox',
- '#title' => t('Make the maximum depth relative to the starting level while following the active menu item.'),
- '#default_value' => $config['depth_relative'],
- '#states' => array(
- 'visible' => array(
- ':input[name=follow]' => array('checked' => TRUE),
- ':input[name=depth]' => array('!value' => '0'),
- ),
- ),
- );
- $form['expanded'] = array(
- '#type' => 'checkbox',
- '#title' => t('<strong>Expand all children</strong> of this tree.'),
- '#default_value' => $config['expanded'],
- );
- $form['sort'] = array(
- '#type' => 'checkbox',
- '#title' => t('<strong>Sort</strong> menu tree by the active menu item’s trail.'),
- '#default_value' => $config['sort'],
- '#description' => t('Sort each item in the active trail to the top of its level. When used on a deep or wide menu tree, the active menu item’s children will be easier to see when the page is reloaded.'),
- );
- $form['parent'] = array(
- '#type' => 'select',
- '#title' => t('Fixed parent item'),
- '#default_value' => $config['menu_name'] . ':' . $config['parent_mlid'],
- '#options' => menu_parent_options($menus, array('mlid' => 0)),
- '#description' => t('Alter the “starting level” and “maximum depth” options to be relative to the fixed parent item. The tree of links will only contain children of the selected menu item.'),
- '#attributes' => array('class' => array('menu-block-parent-mlid')),
- '#element_validate' => array('menu_block_configure_form_parent_validate'),
- );
- $form['parent']['#options'][MENU_TREE__CURRENT_PAGE_MENU . ':0'] = '<' . t('the menu selected by the page') . '>';
- $form['menu-block-wrapper-close'] = array('#markup' => '</div>');
-
- // Set visibility of advanced options.
- foreach (array('title_link', 'follow', 'depth_relative', 'follow_parent', 'expanded', 'sort', 'parent') as $key) {
- $form[$key]['#states']['visible'][':input[name=display_options]'] = array('value' => 'advanced');
- }
- if ($config['title_link'] || $follow || $config['expanded'] || $config['sort'] || $config['parent_mlid']) {
- $form['display_options']['#default_value'] = 'advanced';
- }
+ menu_block_export_ui_form($form, $form_state);
return $form;
}
/**
- * Validates the parent element of the block configuration form.
- */
-function menu_block_configure_form_parent_validate($element, &$form_state) {
- // Determine the fixed parent item's menu and mlid.
- list($menu_name, $parent_mlid) = explode(':', $form_state['values']['parent']);
- $form_state['values']['parent_mlid'] = (int) $parent_mlid;
-
- if ($parent_mlid) {
- // If mlid is set, its menu overrides the menu_name option.
- $form_state['values']['menu_name'] = $menu_name;
- }
-}
-
-/**
- * Validates the follow element of the block configuration form.
- */
-function menu_block_configure_form_follow_validate($element, &$form_state) {
- // The value of "follow" stored in the database/config array is either FALSE
- // or the value of the "follow_parent" form element.
- if ($form_state['values']['follow'] && !empty($form_state['values']['follow_parent'])) {
- $form_state['values']['follow'] = $form_state['values']['follow_parent'];
- }
-}
-
-/**
* Implements hook_block_save().
*/
function _menu_block_block_save($delta = '', $edit = array()) {
if (!empty($delta)) {
- // Don't save values for an exported block.
- $config = menu_block_get_config($delta);
- if (empty($config['exported_to_code'])) {
- variable_set("menu_block_{$delta}_title_link", $edit['title_link']);
- variable_set("menu_block_{$delta}_admin_title", $edit['admin_title']);
- variable_set("menu_block_{$delta}_parent", $edit['parent']);
- variable_set("menu_block_{$delta}_level", $edit['level']);
- variable_set("menu_block_{$delta}_follow", $edit['follow']);
- variable_set("menu_block_{$delta}_depth", $edit['depth']);
- variable_set("menu_block_{$delta}_depth_relative", $edit['depth_relative']);
- variable_set("menu_block_{$delta}_expanded", $edit['expanded']);
- variable_set("menu_block_{$delta}_sort", $edit['sort']);
+ ctools_include('export');
+ $menu_block = ctools_export_crud_load('menu_blocks', $delta);
+ foreach (array_keys((array) $menu_block) as $key) {
+ if (isset($edit[$key])) {
+ $menu_block->{$key} = $edit[$key];
+ }
}
+ ctools_export_crud_save('menu_blocks', $menu_block);
}
}
diff --git a/menu_block.info b/menu_block.info
index f64bcf4..b6ceb12 100644
--- a/menu_block.info
+++ b/menu_block.info
@@ -2,6 +2,7 @@ name = "Menu Block"
description = "Provides configurable blocks of menu items."
core = 7.x
+dependencies[] = ctools
dependencies[] = menu (>7.11)
configure = admin/config/user-interface/menu-block
diff --git a/menu_block.install b/menu_block.install
index 3dfcf2f..b7a0c38 100644
--- a/menu_block.install
+++ b/menu_block.install
@@ -4,19 +4,97 @@
* Provides install, upgrade and un-install functions for menu_block.
*/
+ /**
+ * Implements hook_schema().
+ */
+function menu_block_schema() {
+ $schema['menu_blocks'] = array(
+ 'export' => array(
+ 'key' => 'name',
+ 'key name' => 'Name',
+ 'admin_title' => 'label',
+ 'primary key' => 'name',
+ 'identifier' => 'menu_block',
+ 'default hook' => 'menu_block_defaults',
+ 'api' => array(
+ 'owner' => 'menu_block',
+ 'api' => 'menu_block',
+ 'minimum_version' => 1,
+ 'current_version' => 1,
+ ),
+ ),
+ 'fields' => array(
+ 'name' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'label' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'description' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => FALSE,
+ 'default' => '',
+ ),
+ 'depth' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ 'expanded' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ 'follow' => array(
+ 'type' => 'varchar',
+ 'length' => 16,
+ 'default' => '',
+ ),
+ 'level' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 1,
+ ),
+ 'parent' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'default' => '',
+ ),
+ 'sort' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ 'title_link' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ ),
+ 'primary key' => array('name'),
+ );
+
+ return $schema;
+}
+
+
/**
* Implements hook_uninstall().
*/
function menu_block_uninstall() {
// Delete menu block variables.
- drupal_load('module', 'menu_block');
- $variable_keys = array_keys(menu_block_default_config());
- foreach (variable_get('menu_block_ids', array()) as $delta) {
- foreach ($variable_keys as $key) {
- variable_del("menu_block_{$delta}_{$key}");
- }
- }
- variable_del('menu_block_ids');
variable_del('menu_block_suppress_core');
variable_del('menu_block_menu_order');
@@ -189,8 +267,112 @@ function menu_block_update_7202() {
}
/**
- * Trigger a menu rebuild.
+ * Add database table, migrate variables into database and enable CTools if
+ * availble.
*/
function menu_block_update_7203() {
- // Nothing needed here.
+ // Add database table.
+ $schema['menu_blocks'] = array(
+ 'fields' => array(
+ 'name' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'label' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ 'description' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => FALSE,
+ 'default' => '',
+ ),
+ 'depth' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ 'expanded' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ 'follow' => array(
+ 'type' => 'varchar',
+ 'length' => 16,
+ 'default' => '',
+ ),
+ 'level' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 1,
+ ),
+ 'parent' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'default' => '',
+ ),
+ 'sort' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ 'title_link' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'size' => 'small',
+ 'default' => 0,
+ ),
+ ),
+ 'primary key' => array('name'),
+ );
+ db_create_table('menu_blocks', $schema['menu_blocks']);
+ // Migrate variables into database.
+ foreach (variable_get('menu_block_ids', array()) AS $delta) {
+ $config = menu_block_get_config($delta);
+ db_insert('menu_blocks')
+ ->fields(array(
+ 'name' => $delta,
+ 'label' => $config['admin_title'],
+ 'description' => NULL,
+ 'depth' => $config['depth'],
+ 'expanded' => $config['expanded'],
+ 'follow' => $config['active'],
+ 'level' => $config['level'],
+ 'parent' => "{$config['menu_name']}:{$config['parent_mlid']}",
+ 'sort' => $config['sort'],
+ 'title_link' => $config['title_link'],
+ ))
+ ->execute();
+
+ // Delete old variables.
+ variable_del("menu_block_{$delta}_title_link");
+ variable_del("menu_block_{$delta}_admin_title");
+ variable_del("menu_block_{$delta}_parent");
+ variable_del("menu_block_{$delta}_level");
+ variable_del("menu_block_{$delta}_follow");
+ variable_del("menu_block_{$delta}_depth");
+ variable_del("menu_block_{$delta}_expanded");
+ variable_del("menu_block_{$delta}_sort");
+ }
+ variable_del('menu_block_ids');
+
+ // Enable CTools if availble.
+ if (!module_exists('ctools')) {
+ module_enable(array('ctools'));
+ if (!module_exists('ctools')) {
+ drupal_set_message(t('The Chaos tool suite (ctools) module is required for Menu Block. Menu Block has been disabled.'));
+ module_disable(array('menu_block'));
+ }
+ }
+ drupal_flush_all_caches();
}
diff --git a/menu_block.module b/menu_block.module
index a5bf396..321250f 100644
--- a/menu_block.module
+++ b/menu_block.module
@@ -31,13 +31,12 @@ function menu_block_form_block_admin_display_form_alter(&$form, $form_state) {
* Implements hook_menu().
*/
function menu_block_menu() {
- // @todo Remove this check if block module is re-added as a dependency.
if (module_exists('block')) {
$items['admin/structure/block/add-menu-block'] = array(
'title' => 'Add menu block',
'description' => 'Add a new menu block.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('menu_block_add_block_form'),
+ 'page callback' => 'drupal_goto',
+ 'page arguments' => array('admin/structure/menu_block/add'),
'access callback' => 'menu_block_access',
'type' => MENU_LOCAL_ACTION,
'file' => 'menu_block.admin.inc',
@@ -48,31 +47,23 @@ function menu_block_menu() {
$items['admin/structure/block/list/' . $key . '/add-menu-block'] = array(
'title' => 'Add menu block',
'description' => 'Add a new menu block.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('menu_block_add_block_form'),
+ 'page callback' => 'drupal_goto',
+ 'page arguments' => array('admin/structure/menu_block/add'),
'access callback' => 'menu_block_access',
'type' => MENU_LOCAL_ACTION,
'file' => 'menu_block.admin.inc',
);
}
}
- $items['admin/structure/block/delete-menu-block'] = array(
- 'title' => 'Delete menu block',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('menu_block_delete_form'),
- 'access callback' => 'menu_block_access',
- 'type' => MENU_CALLBACK,
- 'file' => 'menu_block.admin.inc',
- );
}
- $items['admin/config/user-interface/menu-block'] = array(
- 'title' => 'Menu block',
+ $items['admin/structure/menu_block/settings'] = array(
+ 'title' => 'Settings',
'description' => 'Configure menu block.',
'page callback' => 'drupal_get_form',
'page arguments' => array('menu_block_admin_settings_form'),
'access callback' => 'menu_block_access',
- 'type' => MENU_NORMAL_ITEM,
+ 'type' => MENU_LOCAL_TASK,
'file' => 'menu_block.admin.inc',
);
return $items;
@@ -100,7 +91,7 @@ function menu_block_menu_alter(&$items) {
* Implements hook_ctools_plugin_directory().
*/
function menu_block_ctools_plugin_directory($module, $plugin) {
- if ($plugin == 'content_types') {
+ if ($module == 'ctools' && !empty($plugin)) {
return 'plugins/' . $plugin;
}
}
@@ -160,8 +151,52 @@ function menu_block_help($path, $arg) {
* Implements hook_block_view().
*/
function menu_block_block_view($delta = '') {
- $config = menu_block_get_config($delta);
- return menu_tree_build($config);
+ $config = menu_block_config_load($delta);
+ if ($config) {
+ $data = menu_tree_build($config);
+ // Add contextual links for this block.
+ if (!empty($data['content'])) {
+ if (in_array($config['menu_name'], array_keys(menu_get_menus()))) {
+ $data['content']['#contextual_links']['menu_block'] = array('admin/structure/menu/manage', array($config['menu_name']));
+ }
+ elseif (strpos($config['menu_name'], 'book-toc-') === 0) {
+ $node = str_replace('book-toc-', '', $config['menu_name']);
+ $data['content']['#contextual_links']['menu_block'] = array('admin/content/book', array($node));
+ }
+ }
+ return $data;
+ }
+ return FALSE;
+}
+
+/**
+ * CRUD function; Load all menu blocks.
+ */
+function menu_block_load_all($disabled = FALSE) {
+ $menu_blocks = array();
+
+ ctools_include('export');
+ foreach (ctools_export_crud_load_all('menu_blocks') as $menu_block) {
+ if (empty($menu_block->disabled) || TRUE == $disabled) {
+ $menu_blocks[$menu_block->name] = $menu_block;
+ }
+ }
+ return $menu_blocks;
+}
+
+/**
+ * Load the menu block configuration.
+ */
+function menu_block_config_load($delta) {
+ ctools_include('export');
+ $config = ctools_export_crud_load('menu_blocks', $delta);
+ if ($config) {
+ $config->admin_title = $config->name;
+ $config->delta = $delta;
+ list($config->menu_name, $config->parent_mlid) = explode(':', $config->parent, 2);
+ return (array) $config;
+ }
+ return FALSE;
}
/**
@@ -282,6 +317,7 @@ function menu_block_get_exported_blocks() {
*/
function menu_block_get_config($delta = NULL) {
static $defaults, $exported;
+ watchdog('menu_block', 'menu_block_get_config() is deprecated and will be removed in the future');
if (!isset($defaults)) {
$defaults = menu_block_default_config();
@@ -323,7 +359,7 @@ function menu_block_get_config($delta = NULL) {
// Split out the 'parent' item into 'menu_name' and 'parent_mlid'.
if (!isset($config['menu_name']) && !isset($config['parent_mlid'])) {
- list($config['menu_name'], $config['parent_mlid']) = explode(':', $config['parent']);
+ list($config['menu_name'], $config['parent_mlid']) = explode(':', $config['parent'], 2);
}
$config['delta'] = $delta;
@@ -377,7 +413,7 @@ function menu_tree_block_data(array &$config) {
// Prune the tree along the active trail to the specified level.
if ($config['level'] > 1 || $config['parent_mlid']) {
if ($config['parent_mlid']) {
- $parent_item = menu_link_load($config['parent_mlid']);
+ $parent_item = menu_block_menu_link_load($config['menu_name'].":".$config['parent_mlid']);
if (!$parent_item) {
watchdog('menu_block', "Menu block @delta is set to use parent menu link @plid but the menu link was not loadable or does not exist.", array(
'@delta' => $config['delta'],
@@ -416,6 +452,26 @@ function menu_tree_block_data(array &$config) {
}
/**
+ * Load a menu link by its menu_name:link_path identifier.
+ */
+function menu_block_menu_link_load($identifier) {
+ //dpm(debug_backtrace());
+ list($menu_name, $link_path) = explode(':', $identifier, 2);
+ $link = db_select('menu_links')
+ ->fields('menu_links', array('mlid'))
+ ->condition('menu_name', $menu_name)
+ ->condition('link_path', $link_path)
+ ->addTag('features_menu_link')
+ ->execute()
+ ->fetchAssoc();
+ if ($link) {
+ //$link['options'] = unserialize($link['options']);
+ return menu_link_load($link['mlid']);
+ }
+ return FALSE;
+}
+
+/**
* Returns the current page's menu.
*
* @return string|bool
@@ -956,36 +1012,6 @@ function menu_block_menu_delete($menu) {
menu_block_menu_order_set_menu($menu['menu_name'], FALSE);
}
-/**
- * Delete a menu block.
- *
- * @param string $delta
- * The delta of the menu block.
- */
-function menu_block_delete($delta) {
- // Since this used to be a form callback, prevent unintentional uses.
- if (is_array($delta)) {
- variable_set('menu_rebuild_needed', TRUE);
- return;
- }
-
- $block_ids = variable_get('menu_block_ids', array());
- $index = array_search($delta, $block_ids);
- if ($index !== FALSE && $config = menu_block_get_config($delta)) {
- module_invoke_all('menu_block_delete', $config);
-
- // Remove the delta from the list of custom IDs.
- unset($block_ids[$index]);
- sort($block_ids);
- variable_set('menu_block_ids', $block_ids);
-
- // Remove all the individual variables.
- $variable_keys = array_keys(menu_block_default_config());
- foreach ($variable_keys as $key) {
- variable_del("menu_block_{$delta}_{$key}");
- }
- }
-}
/**
* Implements hook_menu_block_delete() on behalf of block.module.
diff --git a/plugins/content_types/menu_tree/menu_tree.inc b/plugins/content_types/menu_tree/menu_tree.inc
index e57eded..f15dbaa 100644
--- a/plugins/content_types/menu_tree/menu_tree.inc
+++ b/plugins/content_types/menu_tree/menu_tree.inc
@@ -18,7 +18,7 @@ $plugin = array(
);
// Load the standard config form.
-module_load_include('inc', 'menu_block', 'menu_block.admin');
+module_load_include('inc', 'menu_block', 'plugins/export_ui/menu_block');
/**
* Supplies a list of menu tree content sub-types.
@@ -107,21 +107,21 @@ function menu_block_menu_tree_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
// Create a pseudo form state.
- $sub_form_state = array('values' => $conf);
- $form += menu_block_configure_form($form, $sub_form_state);
+ $sub_form_state = array('item' => (object)$conf);
+ menu_block_export_ui_form($form, $sub_form_state);
// Hide the menu selector.
$form['menu_name']['#type'] = 'hidden';
// Set the options to a simple list of menu links for the configured menu.
$menus = menu_block_get_all_menus();
- $form['parent']['#options'] = menu_parent_options(array($conf['menu_name'] => $menus[$conf['menu_name']]), array('mlid' => 0));
+ $form['parent_mlid']['#options'] = menu_parent_options(array($conf['menu_name'] => $menus[$conf['menu_name']]), array('mlid' => 0));
// Hide the Parent item option for the special "active" menu.
if ($conf['menu_name'] == MENU_TREE__CURRENT_PAGE_MENU) {
- $form['parent']['#type'] = 'hidden';
+ $form['parent_mlid']['#type'] = 'hidden';
}
// Remove CSS class hooks for jQuery script on parent select.
- unset($form['parent']['#attributes']);
+ unset($form['parent_mlid']['#attributes']);
return $form;
}
@@ -134,7 +134,7 @@ function menu_block_menu_tree_content_type_edit_form_submit(&$form, &$form_state
$form_state['conf'][$key] = $form_state['values'][$key];
}
if (!empty($form_state['values']['parent'])) {
- list($form_state['conf']['menu_name'], $form_state['conf']['parent_mlid']) = explode(':', $form_state['values']['parent']);
+ list($form_state['conf']['menu_name'], $form_state['conf']['parent_mlid']) = explode(':', $form_state['values']['parent'], 2);
}
}
@@ -147,7 +147,8 @@ function menu_block_menu_tree_content_type_admin_title($subtype, $conf, $context
}
else {
// Build the menu tree.
- $output = _menu_block_format_title($conf);
+ $menus = menu_block_get_all_menus();
+ $output = t('Menu tree') . ': ' . $menus[$conf['menu_name']];
}
return $output;
}
diff --git a/plugins/export_ui/menu_block.inc b/plugins/export_ui/menu_block.inc
new file mode 100644
index 0000000..3573937
--- /dev/null
+++ b/plugins/export_ui/menu_block.inc
@@ -0,0 +1,232 @@
+<?php
+/**
+ * @file
+ * CTools Export UI plugin for Menu Block.
+ */
+
+/**
+ * CTools Export UI required function for plugin definition
+ */
+function menu_block_menu_block_ctools_export_ui() {
+ return array(
+ 'schema' => 'menu_blocks',
+
+ 'menu' => array(
+ 'menu prefix' => 'admin/structure',
+ 'menu item' => 'menu_block',
+ 'menu title' => 'Menu Blocks',
+ 'menu description' => 'Administer Menu Blocks.',
+ ),
+
+ 'title singular' => t('menu block'),
+ 'title singular proper' => t('Menu Block'),
+ 'title plural' => t('menu blocks'),
+ 'title plural proper' => t('Menu Blocks'),
+
+ 'handler' => 'menu_block_ui',
+
+ 'form' => array(
+ 'settings' => 'menu_block_export_ui_form',
+ ),
+
+ 'export' => array(
+ 'admin_title' => 'label',
+ 'admin_description' => 'description',
+ ),
+ );
+}
+
+/**
+ * Menu Block settings form.
+ */
+function menu_block_export_ui_form(&$form, &$form_state) {
+ list($form_state['item']->menu_name, $form_state['item']->parent_mlid) = explode(':', !empty($form_state['item']->parent) ? $form_state['item']->parent : 'main-menu:0');
+
+ $form['#attached']['js'][] = drupal_get_path('module', 'menu_block') . '/menu-block.js';
+ $form['#attached']['css'][] = drupal_get_path('module', 'menu_block') . '/menu-block.admin.css';