2

While working on the layout of a new custom menu, I discovered that the hook_menu process is not working on my D7.12 local site. As a test I enabled the Menu_example module and found that it will not generate menu items in the navigation menu, although it did a week or two ago. So far I have reinstalled all Drupal 7.12 files and confirmed that the module file hook_menus are being read (using dsm). I am at a loss as to what else can be preventing the menu links from being installed.

Does anyone have any similar experiences or suggestions on how to track this problem down to its source?

EDIT: This code does not add a menu item in an empty menu called "Stuff":

function material_menu_menu (){
  $items['stuff/existing'] = array(
    'title' => '020000 Existing', 
    'page callback' => 'material_view' , 
    'page arguments' => array ('sum' , '020000 '), 
    'type' => MENU_NORMAL_ITEM, 
    'menu_name' => 'Stuff',   
    'access callback' => TRUE,
    'weight' => '2 ');
  return $items;
}
7
  • I think the menu_name would normally be case sensitive so it should be 'stuff' rather than 'Stuff' to match up with the menu's machine name. Also your code above doesn't return $items;...could either of these be the problem? – Clive Mar 13 '12 at 18:24
  • 1
    I did have return $items but forgot to add it in this text. I'll check on case sensitivity, but that does not explain why the menu_example module is not working now. I had it enabled in the navigation menu when I was preparing to work on this menu, but when I re-enabled it, it no longer shows up. – Ashlar Mar 13 '12 at 18:30
  • I changed the case without a change in the problem. I have also flushed caches. I sure do love these Drupal engimas!!! :) – Ashlar Mar 13 '12 at 18:36
  • 1
    Yeah I didn't think that'd fix it but it was worth a shot :) The place to start debugging is in _menu_navigation_links_rebuild() which builds up the menu links...it gets passed the menu router items built up from menu_router_build() (which is where hook_menu() is called from). A bit of temporary debug code in that first function would be the best way to go I think – Clive Mar 13 '12 at 18:36
  • OK, some progress! I added dsm's to both drupal functions and found that the menu item was being included. Curiously, the menu_example menu finally showed up in the navigation menu. I have no Idea why it took so many iterations of toggling the module on and off to finally get it to appear (at least 5 cycles). I parts of drupal code cached so that whatever may have been causing the omission of the menu was not readdressed until I altered the code in the core module? – Ashlar Mar 13 '12 at 19:37
2

The place to start debugging is in _menu_navigation_links_rebuild() which builds up the menu links...it gets passed the menu router items built up from menu_router_build() (which is where hook_menu() is called from). A bit of temporary debug code in that first function would be the best way to go I think.

To address your other question, I've just added a menu item to a module in exactly the way you've done and it's come up in the UI as expected. It sounds like you have something pretty unusual happening with your menus!

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.