If I try to save a new menu item with menu_link_save, but specify a non-existant path, the item is not saved, but the function (menu_link_save) returns an id (it should return FALSE.
If I try to save a new menu item with menu_link_save, but specify a non-existant path, the item is not saved, but the function (menu_link_save) returns an id (it should return FALSE.
Comments
Comment #1
Sam Dark commentedCan confirm the issue.
Comment #2
johanneshahn commentedmenu_link_save() function needs a valid menu item.
with the menu_form the new menu item path ($item['link_path'])
is validated with function menu_edit_item_validate()
see: http://api.drupal.org/api/function/menu_edit_item_validate/6
if you call menu_link_save() directly you need a valid menu item.
i think its not a good solution to check valid paths twice. once at menu_edit_item_validate()
and once at menu_link_save().
Comment #3
alexiswatson commentedThat assumes that menu_link_save() isn't being invoked programmatically, outside of the normal use case in which it would already be validated first. While I agree that double-handling should be avoided where it can be helped, I don't know if that's the case here. Reading the documentation, it says nothing about the params of menu_link_save() requiring validation before being passed in, and claims that FALSE is returned if the item didn't save. If it isn't returning FALSE on failure, it's a bug.
Comment #4
seanberto commentedFollowing to see where this goes. I agree with c.ex after stumbling to debug a similar issue.
Comment #5
alexiswatson commentedThis still appears to be an issue in D7. I'm not sure whether the bug is in the documentation ("The mlid of the saved menu link, or FALSE if the menu link could not be saved due to the maximum depth being exceeded," which doesn't make as much sense) or the code (not returning FALSE when failing to save for other reasons), but one of these is clearly incorrect. Any ideas?
Comment #6
spesic commentedBumping this, menu_link_save shouldn't return mlid if the call is not successful.