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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With