Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7: How to Create a Menu/Route Item That Doesn't Appear in the Site Navigation

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?

like image 402
Alan Storm Avatar asked Mar 02 '11 16:03

Alan Storm


2 Answers

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.

like image 86
wildpeaks Avatar answered Sep 30 '22 10:09

wildpeaks


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.

like image 24
Berdir Avatar answered Sep 30 '22 10:09

Berdir