-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfixtures.menu.inc
50 lines (47 loc) · 1.72 KB
/
fixtures.menu.inc
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
<?php
function fixtures_create_menus() {
// Getting an array of fixtures, all files in the fixtures folder, that have 'menu--' as a beginning string
$fixtures = fixtures_get_fixtures('menu');
foreach ($fixtures as $fixture) {
foreach ($fixture as $menu_name => $menu_array) {
// entering loop for each defined menu in this file.
// check if menu with key doesn't already exist, otherwise create new menu
$menu = menu_load($menu_name);
if (!$menu) {
$menu = array();
$menu['menu_name'] = $menu_name;
$menu['title'] = $menu_array['title'];
$menu['description'] = $menu_array['description'];
menu_save($menu);
drupal_set_message(t("Created menu #name.", array('#name' => $menu_name)));
}
else {
drupal_set_message(t("Menu #name already exists.", array('#name' => $menu_name)));
}
// Create menu items
_fixtures_create_menu_item($menu_array['items'], $menu, 0);
}
}
return "debugging fixtures";
}
function _fixtures_create_menu_item($items, $menu, $plid = 0) {
foreach ($items as $item_key => $item_value) {
$item = array();
$path = path_load(array('alias' => $item_value['link']));
if ($path) {
$item['link_path'] = $path['source'];
}
else {
// Default path if no path is found or the current menu item.
$item['link_path'] = 'node';
}
$item['module'] = 'fixtures';
$item['link_title'] = $item_value['title'];
$item['menu_name'] = $menu['menu_name'];
$item['plid'] = $plid;
menu_link_save($item);
if (array_key_exists('items', $item_value) && is_array($item_value['items'])) {
_fixtures_create_menu_item($item_value['items'], $menu, $item['mlid']);
}
}
}