1

According to the last paragraph:

https://api.drupal.org/api/drupal/includes%21menu.inc/group/menu/7

Everything described so far is stored in the menu_router table. The menu_links table holds the visible menu links. By default these are derived from the same hook_menu definitions, however you are free to add more with menu_link_save()

I need to do the reverse of that, which API do I use? I need to add a record to the routing table but not couple that to an visible menu link...

The only way I can think (short of manually INSERT'ing) is to initialize a hook_menu call somehow with the various paths I want and call menu_rebuild()??? This appears to be how Panels does it...

Suggestions, opinions, etc???

EDIT | Why isn't this code working...resulting in "The requested page "/test" could not be found."

function test() {
  return 'Do something';
}

function pagegrid_menu_hook() {
  $items = array();

  $items['test'] = array(
    'type' => MENU_CALLBACK,

    'title' => 'TEST',

    'page callback' => 'test',
    'access arguments' => array('access content')
  );

  return $items;
}

1 Answer 1

0

Menu links are only created by default because the default type for a router item is MENU_NORMAL_ITEM:

Menu type -- A "normal" menu item that's shown in menu and breadcrumbs.

What you need is a MENU_CALLBACK:

Menu type -- A hidden, internal callback, typically used for API calls.

e.g.

$items['example/feed'] = array(
  'title' => 'Example RSS feed',
  'page callback' => 'example_feed',
  'access arguments' => array('access content'),
  'type' => MENU_CALLBACK,
);

That will create you an accessible path with no menu links, unless of course you add them manually through code or the UI.

5
  • Excellent thank you...I literally just stumbled across that...for several years I have struggled with Drupal menus and suddenly they make sense :) thanks again...always a help Jun 17, 2014 at 20:01
  • Happy to help :)
    – Clive
    Jun 17, 2014 at 20:07
  • i'm getting a page cannot be found...any common reasons for this to occur? I literally copied some example code verbatim from various tutorials...making sure the $items keys were correct and still no luck... Jun 17, 2014 at 20:43
  • 1
    Take a look at the name of your hook_menu implementation...it should be MODULE_menu()
    – Clive
    Jun 17, 2014 at 20:46
  • Ugggh...sorry...such a petty error... :) Thank you very much...but again. Jun 17, 2014 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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