Ways to shoot yourself in the foot: Custom module and theme names

Submitted by Marc on Thu, 04/04/2013 - 4:00pm

I was writing an extremely simple custom module (for a D6 site) to make use of hook_block. Every time I enabled the module the blocks no longer displayed on the pages. Since it had been a long time since I had done any work in D6, I figured there must be something I was overlooking in how I wrote the function. If I disabled the module (or even just commented out the hook_block) function then the blocks reappeared. So, I spent a fair amount of time looking over how I had written the hook. But, I couldn't see anything wrong with it.

Next, I tried the usual fix-all of clearing cache. In fact, I cleared it two times in a row just to be sure. I also looked for any entries in error logs, including the watchdog file and the server error logs, and didn't find anything.

In the process of testing, I re-enabled the module and uncommented the function and things seemed to just start working again. I thought to myself, "Must be gremlins in the server." (Actually, I typed it out in the IRC channel.) But, the site was apparently working again, so I went on my way. Naturally, the problem cropped up again.

Since it seemed to be a sporadic error, I thought that it must be related to something with the server setup. So, I tested whether increasing the memory_limit or max_execution_time had any effect to no avail. Out of desperation I thought about just changing the name of the custom module, and a light finally went on! I realized that I had named the custom module the same thing as the custom theme. So, the situation was that I had /sites/mysite/themes/mycustomname/mycustomname.info as well as /sites/all/modules/custom/mycustomname/mycustomname.info and /sites/all/modules/custom/mycustomname/mycustomname.module. This lead to the function being named function mycustomname_block($op = 'list', $delta = 0, $edit = array()).

Once I renamed the module everything worked just as expected. I haven't investigated where in the process things broke between the module and the theme layer. The theme is a sub-theme of Omega and there is an empty preprocess-block.inc file in the /sites/all/themes/omega/preprocess directory. But, there is no implementation of hook_preprocess_block in the template.php for the custom theme or the base theme.

So, the moral of the story is: Whenever you are working on a site make sure that your theme names and your module names are distinct.