Cleanly overriding core modules in Drupal through the magic of multisite
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?
- Login to post comments













Restriction?
I take it that this will not apply to the "core required" set of modules (block, filter, node, system, user, watchdog), since your instructions say that you have to disable the module before you can do so.
The required set cannot be disabled.
Good question
Actually, this DOES apply to core modules as well. You can't disable them using the GUI, so you could set the file path directly in the database (or move them out of the way, clear the cache, and have the overriden module in place...tricky).
Don't need to touch
Don't need to touch database, actually, just have the new core module in place and clear the cache. It is really a nice way to have patched core modules I use a lot.
it seems charming but not long lasting!
hello Boriss,
your approach is quite tricky and might be useful too but i feel that this is not the way that Drupal suggest to customize core module.
I appreciate your effort and thinking as i used this technique for me too. I used your trick for 2 times, 1st when i was in need to add some new fields in 'contact' module (core - not required) and your trick worked but it got problematic when i customized 'node' module of Drupal (core - required) and i was totally trapped to disable my custom node module after enabling that.
I'll suggest to all readers of this post to concentrate on these urls before adopting this trick:
http://drupal.org/node/214592#comment-715553
http://symbiotix.net/articles/how-add-one-or-more-custom-submit-handlers...
http://drupal.org/node/351183
These topics will realy help you understand the idea of core module customization.
Thanks