Editing contributed modules best practices?

rhughes - September 17, 2009 - 15:27

Hello,

I have a couple of functions in a contributed module (Webform) that I wish to edit, I understand that is not a good practice to directly edit the original file so I was wondering what the best practice is to overwrite the functions already defined in the webform_report.inc file.

The 2 functions I wish to edit are:

-function theme_webform_results_table

-function theme_webform_results_table

If that is of any additional help.

Thanks,

rhughes

Two things which I would do

kkinfy - September 17, 2009 - 15:36

Whenever I want to edit modules I would certainly do two things:

1) Have a back up of the module
2) I would include my changes with lot of comments for easy analysis therafter

KK (Kamalakannan)
India CareersInformation Portal
One Dollar Deal on Facebook

I guess what I was trying to

rhughes - September 17, 2009 - 15:40

I guess what I was trying to say is, where do I put my code which overwrites the original functions?

Theme functions

matkeane - September 17, 2009 - 16:10

Hi,

Those functions you mentioned are themable functions - i.e. they are designed to be overridden.

You can override a theme function by creating a function in your theme's template.php file and prefixing it with your theme's name, so for a theme called 'mytheme', you'd add a function called:

function mytheme_webform_results_table()

So, copy the function you want to modify into your template.php file, rename it, hack it anyway you want to and ... nothing will show up! You also need to declare that your theme has overridden that function by adding it to the list of your theme functions using hook_theme:

function mytheme_theme()

... and then you need to clear the theme registry, which you can do by clearing the caches on the 'site configuration > performance' admin page. Now, your modified theme function will take over the rendering of that part of the output.

More info here: http://drupal.org/node/341628

This way exactly what I was

rhughes - September 17, 2009 - 18:23

This way exactly what I was looking for but didn't quite know how to articulate it. Thanks for the help.

 
 

Drupal is a registered trademark of Dries Buytaert.