Cleanly Overriding Core Modules in Drupal through the Magic of Multisite

· 2 min read

Original publication

This post was originally published on April 2, 2007 on The Standard, the Raincity Studios blog, credited to “Boris Mann”. This post reflects the context and tools of its time; some links and services mentioned no longer exist.

View the original on the Internet Archive

I recently got an email from Mark Shropshire (apparently emailing from the depths of a secret research lab at UNCC) asking about an article I had written giving feedback on one of IBM's Developerworks articles, where I talked a bit about some best practices around multisite, symlinks, etc.

The bit that got him interested was this paragraph:

Overriding a core module is no problem. Any core module you place in /var/www/html/sites/domain.com/modules will override the main install core module. This is a safe way to have patched core modules without having to wonder if you'll run into trouble updating your main Drupal install.

Yes, it's true. With the power of Drupal's magic multisite file path scanning, you can place a module in your local sites/domain.com/modules directory and it will override modules that are "higher" up the search path. But, Drupal tries to thwart you by sneakily caching the file path to modules in the system table, which only refreshes when you go to the Admin / Modules page. Here's how to get that "local" module enabled instead:

0. Put your site in offline mode
1. Go to admin/modules (4.7 and earlier) or admin/build/modules (5.0 and up)
2. *Disable* the core module you want to override and submit the page (you should already have the override module in place)
3. Re-enable the same module, and you should now be running the "overridden" version

How can you tell the order of operations where Drupal looks? Check the conf_path function on the API site (that link is for HEAD, it's slightly different for 4.7 and earlier). To start using the "core" module again, reverse the steps, except you need to then actually move the local module out of the way so the "core" module can again be recognized.

For Drupal 5, there is actually a whole additional area to look for modules: the profiles directory (e.g. profiles/drupal_wiki/modules). This is a bit strange if you don't know about it, since there is no way to tell by looking at the local sites folder about these "extra" modules that are made available by the install profile. Did I mention symlinking is going to come in handy?

Your business deserves to be found.

Tell us about your project. We answer in English or French, and we travel anywhere in the MRC de Papineau.

Display

Your choices stay in this browser. Nothing is sent.

Text size
100%
Colours
Reading
More help
Site accessibility