2

I created a module containing the following files:

  • menu_imoveis.info
  • menu_imoveis.module

The content of menu_imoveis.info is the following.

    name = Menu Imoveis
    description = Adiciona imoveis ao menu.
    package = Imoveis
    core = 7.x
    version = 7.x-dev

    files[] = menu_imoveis.module

**The content of menu_imoveis.module is the following.

function menu_imoveis_menu() {
  $items['node/27'] = array(
    'title' => 'Example Page',
    'menu_name' => 'main-menu',
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

The code I wrote doesn't work.

4
  • Did you clear your cache "Admin -> Config -> Performance -> clear cache". Or drush cc all. When you use hook_menu() you should clear your cache to see the changes. Also, I get you speak 2 languages -- I recommend trying to write your code in 1 language (english) so it's more maintainable.
    – tenken
    Jun 14 '12 at 21:13
  • Tanks tenken, But I clear the cache and run cron.
    – Eduardo
    Jun 14 '12 at 21:15
  • Where is the page callback?
    – AKS
    Oct 21 '12 at 22:17
  • It's not clear what you're trying to accomplish. I suggest menu_example for learning how Menu API works: api.drupal.org/api/examples/menu_example%21menu_example.module/…
    – paul-m
    Jan 1 '13 at 18:42
1

Taken from this comment, written by zifiniti:

I was having trouble getting a menu item to display with the following code:

function mymodule_menu() {
  $items['custom-page'] = array(
    'title' => 'Custom Page',
    'menu_name' => 'main-menu',
    'access arguments' => array('access custom pages')
  );

  return $items;
}

It was continuously denying me access to the specified path in addition to not displaying the item in the menu. I discovered that the reason behind this is if you do not specify a page callback, then the access callback will acquire a value of 0 in the database and thus render that path/menu item inaccessible.

Working code:

function mymodule_menu() {
  $items['custom-page'] = array(
    'title' => 'Custom Page',
    'menu_name' => 'main-menu',
    'page callback' => 'mymodule_custom_page',
    'access arguments' => array('access custom pages')
  );
}
0

Ok Looking at it you are trying to edit a menu item which is already created. So you need to use the HOOK_menu_alter function.

function  mymodule_menu_alter(&$items) {
  $items['node/27']['title'] = 'Something';
}

Also you might need to clear cache for this function to be triggered.

2
  • Actually, node/27 is not defined; it is node/%node that is defined.
    – apaderno
    Sep 21 '12 at 0:35
  • Yes that is correct. My mistake.
    – junedkazi
    Sep 21 '12 at 4:05

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.