Skip to Navigation

Drupal Module and Theme Naming Collisions

Printer-friendly version

As good as Drupal is, as many third-party enhancements there are, there usually comes a time when they just aren't quite enough. The answer to that is to create your own module that does exactly what you or your client needs. And since they are for a particular site the natural inclination is to name them after that site. Similarly when developing a theme for a site the natural inclination is to name the theme for the site. This, unfortunately, is a Very Bad Thing (TM). For why this is let's take a quick look at where the configuration for modules and themes ends up, the system table.

A quick export shows us the following:

CREATE TABLE `system` (

  `filename` varchar(255) NOT NULL default '',

  `name` varchar(255) NOT NULL default '',

  `type` varchar(255) NOT NULL default '',

  `description` varchar(255) NOT NULL default '',

  `status` int(11) NOT NULL default '0',

  `throttle` tinyint(4) NOT NULL default '0',

  `bootstrap` int(11) NOT NULL default '0',

  `schema_version` smallint(6) NOT NULL default '-1',

  `weight` int(11) NOT NULL default '0',

  PRIMARY KEY  (`filename`),

  KEY `weight` (`weight`)

)

The important rows are filename, which holds the file included for the module or the stylesheet displayed for the theme; name, which holds the name of the module or theme; type which is either module or theme; and description which holds the description of the module or the path to the templating engine for themes. While I could take a slight detour to talk about why this structure is a bad idea (hint, it involves using the same column to mean two different things -- bad, Drupal, bad), it only partly contributes to our problem.

When the theme and module have the same name and a user goes to the theme administrative section it updates all rows in the system table with the name of the theme to have the correct filename and description/templating engine. It, however, does not check for the type. So when it finds the module with the same name it overwrites it. So you end up with a row that has a type of module but has the filename of a CSS file, and when the system goes to include all modules that are active it grabs the CSS and you end up with it output at the very top of the page. Oh, and any functionality that your module provided no longer works.

So the moral of the story is don't name themes and modules the same.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.