Never name a theme and a module the same thing

10.08.2008

Lets say you're building a drupal website for Bill's Widget Company. You create a custom theme, and a custom module. Now lets also say you are as dumb as me, and decided to name both your theme and module the same thing: bwc. Its a small mistake you'd never make if you thought for a second: "Should my module and theme share the same drupal namespace?" It sounds dangerous, even if you don't know why. Here's why it is dangerous:

The first sign of trouble happened as soon as I added an implementation of hook_form() "bwc_form" to bwc.module. Not only did my form not work, but NO form worked. All forms returned as "array", and frequently had incorrect data types being passed (stdClass's where there should have been an array and vice versa). It was a bit embarrassing how long it took me to figure out the obvious cause:

Since my theme (themes/bwc/bwc.info) shared the same namespace as my module (bwc.module), the theme system mistakenly interpreted bwc_form(&$node) as an override to theme functions: 1. phptemplate_form, and 2). theme_form.

Hopefully, whoever makes this mistake next will find this answer.

Comments

That's happened to me on more

That's happened to me on more projects than I care to admit. There's nothing quite like pounding your head on a keyboard for an hour trying to fix a problem that shouldn't be broken in the first place. Just today I had a Drupal 5 theming project where all my regions disappeared after clearing out the contents of my theme_regions function, as if not having any regions would cause Drupal to default to the regular regions or something. *sigh*

Brandon
TFnS Web Design

I'm sure we've all been there

I know I've been there.

Another such pitfall is accidentally implementing a hook without thinking.

This page is going to load something on Bill's Widget Company site... lets do a menu callback to bwc_load...
bad idea :)

andre

Haha, here's a few of my

Haha, here's a few of my favorite recent gotchas I've run into:
1. (I forgot this gotcha, its either: name a menu callback's function something with the string "callback", or map it to a path that contains the string "callback".... I think its the latter, and it absolutely doesn't work.).
2. Using hook_form_alter when you should have been using $form['#theme']
3. Using hook_view instead of node.tpl.php

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options