Create your own custom override module

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, 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.
custom.module
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

Add comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags
  • Lines and paragraphs break automatically
  • Websites and email addresses turn into links automatically

jsfwd on Twitter 

  • 13 hours 13 min ago hot damn rock vs rap!! thanks json RT @jswaby: @jsfwd http://www.sfspodcast.com rock vs rap
  • 13 hours 27 min ago #Raptors taking 5th seed back tonight! (with a little help from Boston)
  • 1 day 17 hours ago Two screens are better than one. I want. RT @BeCircle Yeah - iPad pwned by Courier. Way cooler and way more useful. http://bit.ly/aO4DqS
  • 4 days 18 hours ago World's largest gummy bear?!? http://www.giantgummybear.com I want one!
  • 5 days 21 hours ago Firefox 3.5 supports the word-wrap CSS property, finally :)
  • 6 days 12 hours ago Has anyone using #drupal and #mollom had any spam problems after upgrading from 6.x-1.10 to 6.x-1.12?
  • 6 days 12 hours ago @mollom has been almost flawless at blocking spam, but now cleaning uber-spam that started after upgrading the drupal module to 6.x-1.12.
  • 2 weeks 1 day ago February Drupal Toronto Meetup tonight... Topic: 'All about hosting' http://bit.ly/d8xM20
  • 2 weeks 5 days ago Since my earlier tweet re: http://pleaserobme #foursquare I've received over 7000 new opportunities! Who says there's a recession?
  • 2 weeks 5 days ago Tweeting your location can be hazardous to your home http://pleaserobme.com #foursquare
more jsfwd on Twitter »
i heart monkeys