I have a code debugging question.
I am implementing hook_menu() for a very simple module and none of my custom menu items in the .module file are showing or working. Any suggestions of how one would start diagnosing this type of issue? Do you use Devel module? Firebug with the Drupal Add-On? Does some IDE let you debug Drupal well? I care less about my project and more about best practices for troubleshooting code when you are developing a module.
All I am doing is following the instructions in a beginner's Drupal module development guide, ie copying and pasting code , so I'm fairly sure the code is correct. I should add, the module shows up in the Module listing, it lets me "Install" it, and the hook_help() implementation for this module does work.
Thanks in advance!
Comments
I don't believe any of those
I don't believe any of those solutions will help you diagnose hook_menu() issues.
Double check the spelling of all your keys, and make sure you haven't used an underscore when you should have. Make sure that _arguments are passed an array and not a string. Make sure you have a page callback function defined and that it exists, and make sure that you have implemented either access arguments, or an access callback (and that the access callback function exists).
You also need to clear the cache after making any hook_menu() changes, as hook_menu() is cached. No changes will show up until you have done this.
Contact me to contract me for D7 -> D10/11 migrations.
Core bugs in custom menus...
I recently added custom menus to a project that I'm involved in (internal development for the company I work with); and I encountered some issues which meant that menu items were not showing up, even after they were created. The main issue I encountered had to do with menu item "children" were not showing if the menu was not set to always be displayed as "expanded" -- the sub-items just didn't display, even if you were on the path that they pointed to.
Anyway, there are a number of core issues regarding custom menus. The one described above is probably best addressed by this bug report:
http://drupal.org/node/942782
I've experimented with the Menu block module (which supposedly fixes the problem), but couldn't seem to get the menus to expand as they should. I've also experimented with the DHTML menu module, which expands the menu parents, but then collapses them again, even when you are active on a "child" path. I think it provides the functionality we wanted, but Drupal's menu system just isn't doing what it should (yet).
Hopefully the fixes are at a stage where we can expect the functionality to be working in Drupal 7.1, whenever that's released.
The issue is that menus with "children" don't expand, even when on one of the child paths. They should expand to show "children" when you click on any parent in the tree.
You may also encounter other issues with custom menus and if you search for the issue you are seeing, you may well confirm for yourself that the problem is not your code, but something that's not quite right in D7 core. You may be able to run a patch (on a related issue) to fix things for yourself (and then hopefully that patch will be included in the next official release), or you may find some other workarounds, but I just thought I'd point out that it's quite possible your menu issues are not in your code.
Best of luck, :-)
Lowell
See you at the Drupalcon!
If you are still having
If you are still having issues, can you post the code that you are using?
--
Read more at iRolo.net
Clear the cache, rebuild menus and... reinsert code
Hi there,
In my experiencie, the drupal cache for the menu system is a bit misbehaving under some circumstances (which of them, I'm not really sure, but maybe I can help you).
Besides clear the cache as Jay told you, I would try to rebuild the menus, which may not fix your problem, but may help with it. The issue here is that even clearing the cache, sometimes "something" doesn't work as expected, and drupal still doesn't recognize your changes in the hook_menu().
What I recommend here is very simple:
1.- Ctrl-X (cut) the entire code relative to the menu items you have defined in the hook_menu(), after you have made there the changes you need, and save the code.
2.- Clear the cache. The menu items you had defined previously should not exist anymore.
3.- Back to the code, copy again the code you took apart in step 1, and save the code.
4.- Flush the cache again. If no menu items appear, rebuild menus (anyways I dont think this is needed after clearing the cache).
After this, you should have your menu items working as you need. if you are working by trial & error maybe you need to do this more than one time. It's a bit annoying, but it worked for me when a simple cache clearing wasn't working as expected.
Not sure why this happens, but the thing is that when working with hook_menu, the cache doesn't work very well.
--author="slv "
Sorry for the delay
I think I've got it. I stepped away from this project for a while. This time, I started over completely and I noticed that I forgot to put:
return $items;at the end of the function. D'oh! That's probably what I did the first time. Thanks everyone for your response!