This can be a very obscure problem. It only happens when I call drupal_execute('menu_edit_item', ...) to import menu programmatically.

If I first call the function and add an menu item, say, to primary links. If I call the method again to add a submenu to the newly created menu (with the proper parent id), the method would fail.

The problem is with the "static" in the code below:

function menu_tree_all_data($menu_name = 'navigation', $item = NULL) {
  static $tree = array(); 

because when $tree was first initialized, my new menu item was not listed under 'primary links'. After I added in my menu item, and came back to the same function again, because $tree is static, it won't pick up the menu item I just added. Therefore, that menu item is not listed as one of parent options. My subsequent call to add a new menu using the previous menu item as the parent would fail! Because the previously added menu item was not in the parent options list. It resulted in a validation error.

I can see the performance reason for the static $tree. I don't know if there is a good work around.

Comments

NROTC_Webmaster’s picture

I think this probably a won't fix in D6 (a maintainer can decide that) but may have already been fixed in D7 by changing the line to

function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) {
  $tree = &drupal_static(__FUNCTION__, array());

with the reference http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupa...

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.