Hi,

I have a test site where I am running the profile wizard. On my test site I have a customised version of the "Navigation" menu - I added some extra menu items to point at some page nodes. When I try to generate a .profile of this site none of my menu items get inserted into the .profile file. I only have the following lines that relate to menus:

    // Primary links
    install_menu_create_menu_items(array (),2);

    // Other menus
    install_menu_create_menu_items(array (),0);

I don't have any primary links configured, so that's not an issue. The nodes themselves, along with their URL aliases, are successfully put into the profile file though.

Could someone have a look at this issue for me? I can send you a dump of my menu table if that would help.

Cheers,
Stella

CommentFileSizeAuthor
#2 menu_recursive_creation.patch1.16 KBalex_b

Comments

tonyp001’s picture

I'm having a similar issue:
I created a custom menu and organized some menu items underneath it. When I ran the profile installation, it created the menu and menu items, but it didn't place the menu items underneath my menu.
Any help would be appreciated.

alex_b’s picture

Title: Doesn't export all menus » Recursive menu creation broken - install_menu_create_menu_items()
Version: 5.x-1.1 » 5.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.16 KB

I found two problems with recursive menu creation in crud.inc:

1) install_menu_create_menu_items() tests for $items['children'] but then iterates through $item['children']

2) install_menu_get_mid($path) can return undefined values if there is more than one menu item with the same path - this leads typically to a bunch of menu items associated with a parent that they shouldn't be associated with.

The attached patch contains a fix that takes the following approach:

1) install_menu_create_menu_items() expects children on $item and hands the children down to the next stage of recursion without any further iteration. I guess everything depends here on the format that install_menu_create_menu_items() expects. This is the function I use for _exporting_ a menu:

/**
 * Export site menus.
 * @return install_menu_create_menu_items() compatible array of menus.
 *   Creates complete menu - doesn't require the use of install_menu_create_menu()
 */
function exportapi_export_menus() {
  // Rebuild menu trees, to catch any recent code changes.
  menu_rebuild();
  $menu = menu_get_menu();
  $root_menus = menu_get_root_menus();
  $output = '';
  foreach (array_reverse($root_menus, true) as $mid => $title) {
    $output .= $title;
    // Wrap into extra array for recursive install_menu_create_menu_items() function.
    $output .= '<pre>'. var_export(array(_exportapi_export_menus_children($mid, $menu['items'])), true) .';</pre>';
  }
  return $output;
}

/**
 * Create recursively a single array of a menu.
 * 
 * @param menu id $mid
 * @param menu items $menu['items'] $menu_items.
 * 
 * @return
 *   Helper function for exportapi_export_menus().
 */
function _exportapi_export_menus_children($mid, $menu_items) {
  $result = $menu_items[$mid];
  unset($result['children']);
  unset($result['pid']);
  foreach ($menu_items[$mid]['children'] as $child_mid) {
    $result['children'][] = _exportapi_export_menus_children($child_mid, $menu_items);
  }
  return $result;
}

2) install_menu_create_menu_item() returns $menu['mid'] rather than install_menu_get_mid($path) - this makes sure that the correct menu id is used as parent id.

boris mann’s picture

Status: Needs review » Closed (won't fix)

Menu stuff is, I believe completely different in 6.x. And PW is deprecated.