What is the relationship between hook menu() and menu_link_save()? I am trying to create a menu using code in D7 (see my related question) and have found that these two Drupal API functions have different arrays for the $item variable. My intent is to create a three level menu hierarchy but with all of the associated paths being the same format /name/%/something so that I can use views to refine the content.  In hook menu, the parents are defined using the Path name (eg. parent/child/something).  In menu_save_link, the hierarchy appears to be established using the pid array value in $item. Hook_menu is called when my custom module is read by drupal and the menu links are established.  What I am wondering is if menu_link_save, could be used to do the same thing but with the same path style for all links, rather than a parent-child pattern?

I have been trying to trace the logic between the two functions in the API, but have not found the link between them.  My thinking is that menu_link_saveis used by hook_menu after some preprocessing and that I might be able to define a uniform paths and establish the hierarchy through the pid.  Failing that, is there another way to alter the paths and preserve the hierarchy?
They're slightly different concepts to be honest; the items defined in hook_menu() are saved in the menu_router table, while menu_link_save() saves items to the menu_links table.

They come together in menu_rebuild():


hook_menu() is invoked through the menu_router_build() function to get a list of router items
The router items are saved to the database using _menu_router_save()
The menu links are generated/updated using _menu_navigation_links_rebuild(); the menu router items are passed to this function to build the links.
Finally the caches are cleared.


There doesn't seem to be any way to pass custom data from the router items to the links I'm afraid, and I don't think hook_menu() supports the sort of hierarchy you're trying to build natively.