Nov 17, 2010
We came across an issue with a site recently, where the name of the custom module file was the same as the name of the theme. So, for example, if the theme name was Bork, the module name was bork.module. This can cause a variety of problems since the two share name space. Problems can include blocks disappearing (both from your site, and from the /admin/build/blocks menu), printing $content returns only 'array,' and more.
There are a few ways you can remedy this. We had already created another module file, called bork_helper.module, so the best option seemed to be to merge the contents from bork.module into bork_helper.module, and rename functions accordingly. It's a relatively easy process as it turns out. I first backed up the database (always, always), disabled the module, merged bork.module into bork_helper.module, and did a search and replace for the function names: bork_form_alter became bork_helper_form_alter, and so on. I initially considered doing this from the command line using sed, so:
sed -i '' -e "s/bork_form_alter/bork_helper_form_alter/g" *
Unfortunately when I did this I got a message, "sed: modules: in-place editing only works for regular files." Meaning, you can't pass this in a directory. If any directories are included in *, sed will fail. Ethan suggested I try using 'find . -type f' instead of * which would search for all files in the current directory and sub directories, but then you also need to exclude .svn which can get tricky.
I opted instead to do it a "simpler" way, and use TextMate's search and replace function. This worked wonders, until I saw after running svn status, that it thought I had edited every single block template in that directory. I hadn't touched any block templates. What I found upon using svn diff was that each file had removed the newline at the end of each of these template files.
In Drupal, it's standard practice for all text files to end in a single newline (\n). This avoids the verbose "\ No newline at end of file'' patch warning and makes patches easier to read since it's clearer what is being changed when lines are added to the end of a file. Read more about it here (I did): http://drupal.org/coding-standards. I still don't quite understand why TextMate did this automatically, but it was at least relatively easy to fix. I reverted to the old block templates.
After merging and renaming functions, I committed the new module file, bork_helper.module back, and re-enabled it via drush. I tested the site, and all was well!
Lessons learned? Never name your module file the same as your theme. But if you happen to inherit a site that does, immediately fix the problem or you'll run into bugs you can't explain.