5

I have to modify a contrib module with a custom function. In my case I can't use hooks to extend it.

Is there a best practice, for example renaming the module and placing in sites/default/modules?

1
  • It depends on the magnitude of change and size of contrib module that you want to customize.
    – Sivaji
    Commented Oct 8, 2011 at 18:16

3 Answers 3

7

If your addition is general and not specific to your site, you could create an issue and post a patch there.

And even if you have a site specific extension, maybe it can be solved in a way that just requires an additional hook to the contrib module itself which could be useful for other use cases as well. Then you could again create an issue for that.

1
  • Yes! This is a mindset. You can always custom code something for your specific use case, but solving it in a way that is useful for others is what open source is about! Commented Aug 3, 2015 at 18:03
4

What I've found useful is to add a contrib and a custom folder, or maybe a contrib-custom folder inside modules folder, there you can move the modules that you've created or contrib modified.

Additionally you need to keep track of the patch that you applied somewhere, maybe a patches folder with the .patch and a readme of the changes.

1
  • It can also be helpful to modify the contrib module's .info file to include the patch number in the version string, like version = "[version]+[issue]-[patch]". E.g. version = "7.x-3.6+2606586-9", though this may cause it to show as having updates available, even if you're using the newest version plus a patch.
    – mbomb007
    Commented Feb 4, 2019 at 20:04
1

Depending on your situation, you can try creating a patch for it so that the module can still be updated and you can re-apply the patch file after updates to the module to keep your customizations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.