One of those fundamentals I skipped over because it gave me a headache to think about thinking about it:

Can someone explain, (or point me to documentation that can explain, and won't make me want to punch myself), the difference, the logic, relationships and/or whatever for "menus" (seemingly misnamed collection of page markers the things you make with HOOK_menu) versus "menus" (thingees that you click on to make events happen the things you make with menu_save())?

...bonus points if you can tell me why in the name of all things holy are log-in, log-out, register, my account, and hell, even "switch back" not built into a single core menu block so that I could continue to live in blissful ignorance...

  • menus === menus. would you elaborate what you mean with the difference between menus and menus? – Елин Й. Jun 23 '14 at 16:16
  • I added detail, I apologize, if I could ask the question clearer I wouldn't need to. Basically, the user menu at the top of the page doesn't have all the links that are part of user-menu. Obviously these are not the same structure, but I imagine they are related. – OhkaBaka Jun 23 '14 at 16:34
  • 2
    Hopefully chx will see this, as he visits from time to time, and I think he wrote the majority of the original menu.module subsystem and can explain this. The main confusion rests from the term "menu item" in hook_menu(). The term "router item" is probably more accurate. The menu hierarchy system and the menu routing system is also a little more tightly coupled that it should be, which adds to the confusion. – mpdonadio Jun 23 '14 at 18:08
  • Tx @MPD, this was my suspicion, that perhaps hook_menu should have been hook_route or something else. – OhkaBaka Jun 23 '14 at 19:00

The main confusion rests in the fact that menu system does two things.

One, it is the subsystem that maps incoming URL requests to functions in Drupal to render output. This is typically called the router. In Drupal 7, routes are defined with hook_menu() and the information gets stored in the {menu_router} table. There are also a group of API functions that deal with the routes and router items, eg

  • menu_set_active_item()
  • menu_get_item()
  • menu_get_object()

Most of these are defined in menu.inc, and many (but not all) have the words "item" or "router" in them.

The other subsystem is what I refer to as the menu hierarchy interface. This creates groups of links into a hierarchy which typically get rendered out to HTML as what we commonly call a menu. The menus themselves are stored in {menu_custom} and the menu entries are stored in {menu_links}. The core functionality is found in menu.inc, but the code related to rendering out a menu is in menu.module. Most (but not all) of the API functions for this have "tree" in the name, eg

  • menu_tree_all_data()
  • theme_menu_tree()

For better or for worse, the two of these are fairly tightly coupled, which adds to the confusion. Fortunately, this is one place where most developers don't need to work directly, other than programming against hook_menu().

|improve this answer|||||

hook_menu : Is used to define a path in Drupal. It also says what should be present in that path, who should have access to it and so.

Documentation of hook_menu

Menus : Is a list of links that fall under a category. For example Admin Menu(Admin Links), User Menu(Account, Logout) and Primary Menu(Home, Contact and so on)

Documentation of Menus

|improve this answer|||||
  • I get what the functions do, which is why I used them in my question, what I'm iffy about is if the products they generate are related (beyond the obvious "if a page doesn't exist, it can't be linked to"). I THINK you answered my question, but to restate (correct me if I'm wrong): Fundamentally different things named the same because Dries is a sadist – OhkaBaka Jun 23 '14 at 18:53

menu_save() is used to create a menu. You can use this to add to the existing system menu (Navigation, Management, User Menu, Main Menu).

hook_menu() Define menu items and page callbacks. You can use this to create a simple callback or a menu item. If you create a menu item by setting $type to MENU_NORMAL_ITEM then you can place this item under any of the menu created using menu_save().

In simple terms

menu_save() - Menu

hook_menu() - Menu Item / Simple Callback

|improve this answer|||||
  • I'd like to hear someone else sound off on this, because I think it is fundamentally wrong, but I am obviously not an expert. The "item" equivalent of menu_save is menu_item_save... that isn't to say menu_item_save and hook_menu aren't near equivalents... but I'm still trying to nail down that concept. – OhkaBaka Jun 23 '14 at 18:57
  • There is no menu_item_save(), do you mean menu_link_save(), if so then menu_link_save() registers an existing path as a menu item. In hook_menu() you are creating the path, callback and optionally registering it as menu item, by setting $type to MENU_NORMAL_ITEM. – wolverine Jun 23 '14 at 19:14
  • Now we're getting somewhere! (and yeah, typo on my part, I did mean menu_link_save)... So 'type' => MENU_NORMAL_ITEM and 'menu_name' => 'whatever' is basically a default menu_item_save() at the time of creation? ...also it would then seem that there isn't a HOOK to create an actual clickable menu? – OhkaBaka Jun 23 '14 at 19:35
  • Yes, setting 'type' => MENU_NORMAL_ITEM will be saved under Navigation menu and menu_name in menu_link_save() can be any menu, but the default is Navigation. – wolverine Jun 23 '14 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.