views:

544

answers:

3

How can I extend an existing module without modifying it? Actually its a contributed module, so I don't want to hack it. But I want to alter and add certain features to it. I'm new to drupal and as I read tutorials about it, I keep hearing one thing again and again - Don't hack the core... and I believe the same applies for modules too.

+1  A: 

What module is it? Some modules provide APIs that you can extend by writing a module of your own. There are tons of modules that "extend" Views by building off of the Views API. If the module you want to extend doesn't have a good API, you can always fork it to make a version that meets your needs. Maybe it will help someone else too.

Jergason
+2  A: 

Avoid hacking or forking the module if at all possible. Hacking the module gives you a lesser variety of the "hacking core" pain, and forking the module (without a distinctly superior architecture and feature set.) just muddies the module water further- making it even more difficult for sitebuilders to make an effective decision about what to use.

The best solutions are:

  1. Use any API provided by the module. Sometimes there are functions you can use as API calls that are not necessarily intended that way.
  2. Create the additional functionality and submit a patch to the module issue queue, so others may benefit from your work, and so you may benefit from security audits without much sweat.
  3. Not always, but often you can go far creating a custom module that implements hook_form_alter and adds a submit handler that leads back to your module for processing.
Grayside
A: 

To change the form shown by the module, you can simply create a module that implements hook_form_alter() or hook_form_FORM_ID_alter(). Most of the times, when you want to modify how a module behave, you also need to change the settings form it uses (or any other form it uses, if it is the case).

kiamlaluno

related questions