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
Comment #1
NROTC_Webmaster commentedI 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
with the reference http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupa...