Modifying contributed Drupal modules

It surprised me that some people think it's not ok to alter contributed modules. Well, its not. It's a bad thing to adjust CORE modules! But that's another discussion. The idea is that before programming your own module you try to find one that already does most of what you want, but misses some features. you will code those features. Sometimes this involves only adding a few lines or adding only one function. Sometimes it involves a lot of programming.

The big problem with altering contributed modules is that you loose the ability to upgrade when a new version of the module is released. In an article about upgrading Drupal, Wim Mostrey proposes a simple solution to keep track of what you are changing.

I started of by dividing the non-core modules between those still in their original state to a "contrib" directory and those that were either completely custom or altered in a "custom" directory, to get the following tree structure:
/sites/all/modules/contrib
/sites/all/modules/custom

This helps you identify what needs to happen and will also save a lot of work for future upgrades. I then started from a clean Drupal 5.3 installation, download the newest version of the modules in /contrib and then started a process of 1) moving the core changes to non-core modules and themes and 2) updating the /custom modules.

But this way, you're only keeping track of what modules have changed. My addition to this tip is that you make a copy of the files you alter and name it .contributed or .original or .backup or .whatever-you-get-my-point (example: tinymce.module.contributed). Now you are keeping track of what files are modified too! And as soon as you need to upgrade, make a quick diff and you know what has changed.

BTW. If you find yourself tweaking a contributed module, why not contribute your new features, improvements? Maybe someone else is looking for it too.

Written on February 27, 2008 at 11:46, tagged as Drupal, module development, tips

Comments

Hi Giovanni, no action is required if you've just added, changed or deleted a few lines of code.

Hi Davy.

I've just patched a file in the Organic Groups module.
Should I uninstall and resinstall (disable and reenable) the entire OG module to make the patch work? I've just added some line of code to og_views.inc, to make OG work better with the Views module.

Thanks and congratulations for your blog.

Giovanni

It's really nice trick, splitting non-core modules in two folders (/sites/all/modules/contrib and /sites/all/modules/custom).
Thanks.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

About

drupalcoder.com is a blog on all things Drupal in specific and LAMP on OS X in general. It is maintained by Davy Van Den Bremt, a Belgian (Drupal) web developer and designer living in Ghent. The goal of this blog is to log all interesting things that have crossed the writer's path while developing Drupal sites. You can read all about Davy's professional activities on his LinkedIn profile. If you want to get in touch, use the contact form.