6

How can I create a new route/menu in Drupal that doesn't automatically render a navigation link?

I'm trying to create a simple page callback in Drupal that doesn't show up in the Navigation menu.

I have a module named helloworld.

The .module file contains the following

function _helloword_page_callback()
{
    return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you
    for following conventions.');
}

function helloworld_menu()
{
    $items['helloworld'] = array(
      'title'               => 'Hello World',
      'page callback'       => '_helloword_page_callback',
      'access arguments'    => array('content'),
      'type'                => MENU_CALLBACK
    );
    return $items;
}

This successfully exposes a URL on the site of

http://example.drupal.com/helloworld

However, I'm still getting a link in the left hand (Bartik) navigation menu, despite the use of

'type'              => MENU_CALLBACK

So, why isn't this working? Am I configuring the Menu item correctly? A more likely question: How am I misinterpreting the use of the menu type constants/system? Are there additional caches to clear that

drush cc all

wouldn't take care of? What other steps can I take to debug this?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Alana Storm
  • 164,128
  • 91
  • 395
  • 599

2 Answers2

6

There must be something else wrong (perhaps you forgot to clear the caches ?) because even with Bartik, it works as expected. In that example, only "Hello 2" is shown in the navigation:

function helloworld_menu(){
    return array(
        'hello1' => array(
            'title'               => 'Hello 1',
            'page callback'       => 'helloworld_page_callback',
            'access arguments'    => array('content'),
            'type'                => MENU_CALLBACK
        ),
        'hello2' => array(
            'title'               => 'Hello 2',
            'page callback'       => 'helloworld_page_callback',
            'access arguments'    => array('content')
        )
    );
}

function helloworld_page_callback(){
    return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you for following conventions.');
}

By the way, there is a typo in your snipplet (helloroute_menu should be named helloworld_menu), but I assume this is due to code simplification before posting on StackOverflow.

wildpeaks
  • 7,273
  • 2
  • 30
  • 35
  • And thanks for the info. Its definitely a cache somewhere. If change my route to a different name (helloworld to helloworld2), the different name the new route doesn't have a menu. It's only when I have a menu item with a default navigation link and I attempt to change it that its not working. (even with a call to drush's cc all, which is another question for another time). Thanks for the sanity check! – Alana Storm Mar 02 '11 at 18:32
  • You're welcome :) And btw, funny "quick brown fox" filler text, I didn't notice at first that it's not the usual quote :D – wildpeaks Mar 02 '11 at 23:26
4

Check out that menu link in the menu administration. If you customized it there (weight change for example), it's possible that it remains even though you set to type to callback.

If that's the case, you can just delete there.

Berdir
  • 6,881
  • 2
  • 26
  • 38