Create Your Own Custom Override Module

Jocelyn's picture
Tags:

If you've ever developed for Drupal, you know that there are times where it seems very tempting to hack a core or contributed module. Maybe you want to change some text, or add in some extra functionality to forms. While yes it might be quicker to hack the module, you're opening yourself up to a lot of potential problems.

  • When new versions of the module come out, they will override any of your hacks
  • You may forget what updates you made
  • You may open up security vulnerabilities
  • If someone new works on the site, they would not be aware of the hacks you made
  • If running a multi-site installation, your hacks could have unintended affects on other sites.

While there may be a rare case where a hack is necessary, in most cases you don't need to.

So how do you cleanly override modules?

For most sites, the best approach is to create a custom override module. This keeps all your modules intact allowing for much easier future upgrades. Too, it centralizes your overrides in one place, which will make any future updates much easier to find and manage.

For anyone new to creating Drupal modules, Page not found.6.x.zip" title="Page not found.6.x.zip (1.76 kb)">attached is a simple skeleton of a Drupal 6 module. You can use this as a spring board for making all your text and behaviour overrides.

Attached module contents

custom.info
.info files are required for Drupal 6.x modules. Basically it lays out naming, description on admin/build/modules, etc...
custom.install
While install files are optional, since this is going to be a custom override module for every module you have installed before or after this one, we need to set the weight of the module. If your module executes before the module you're attempting to override, you won't see any changes. Setting the weight will ensure that your module executes last.
Page not found
This will be where you make all your custom overrides. For more information about hooks, check out http://api.drupal.org/api/group/hooks

Steps

  1. Unzip module to sites/all/modules or wherever you typically install your contributed modules
  2. Optional:
    1. Rename 'custom' folder & files to whatever you'd like to call your custom override module
    2. Replace all occurances of 'custom' within the files to whatever you've decided to name your module
  3. Enable the module at sites/all/modules
Tags:

Comments

Nikos Stylianou's picture

Instead of having to check the form_id inside hook_form_alter to target a specific form, you could just use
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hoo...

Add New Comment