In my project we implement a little menu that provides information about the module. This snippet lives in drutexml.module.

function drutexml_menu() {
  $items['drutexml'] = array(
    'title' => 'LaTeX filter implemented via LaTeXML',
    'page callback' => 'drutexml_information',
    'access callback' => TRUE,
  return $items;

Actually this is a bit silly, and I want to turn it back off inside the installation profile. But as it turns out...

SELECT link_path, module FROM menu_links WHERE link_path = "drutexml";

| link_path | module |
| drutexml  | system |

and then in menu.inc, where menu_link_delete is implemented, we see this bit of logic on line 2997:

if ($item && ($item['module'] != 'system' || $item['updated'] || $force)) { ...

In other words, I can only delete non-"system" links. That's fine with me! Or it would be, if my link was stored with the name of the module where hook_menu is implemented in the first place.

What's going on here? Why is this said to be a "system" link?


The only way to remove a menu item defined from a module in hook_menu() is, apart from removing its definition from the module's hook_menu(), removing it with hook_menu_alter().

function mymodule_menu_alter(&$items) {

Menu items that are part of a menu, including the ones defined with hook_menu(), are saved in the menu_links table. Those defined in hook_menu() are saved setting the "module" field to "system" to distinguish them from other links directly added from a module.

  • What is the alternative to hook_menu() for adding links directly from a module? – Joe Corneli Dec 9 '12 at 22:20
  • 1
    You can use hook_menu(), but use MENU_SUGGESTED_ITEM as type. In that way, the link will appear in a menu if an administrator user enables it. – kiamlaluno Dec 9 '12 at 22:24
  • Or maybe use menu_link_save? Frankly the design decision that says we should "distinguish" hook_menu links from other kinds of links seems weird to me. But any, I think I understand now (sorta). Thanks! – Joe Corneli Dec 9 '12 at 22:28
  • You can also use menu_link_save(), but the module should also remove the link once it is disabled. I prefer using MENU_SUGGESTED_ITEM because the link is automatically removed when the module is disabled; when the module is re-enabled, the link is automatically added where it was before. – kiamlaluno Dec 9 '12 at 22:32
  • 1
    Also, another problem with menu_link_save() is that it doesn't straightforwardly allow me to add a page callback. There's considerable discussion about how this will all be rewritten in D8 anyway, so I'm not going to worry about it too much... – Joe Corneli Dec 9 '12 at 22:44

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.