Drupal Custom or contrib

Drupal Module Development : Custom or Contributed?

INTRODUCTION:

At the start of applying every requirement that I come across, the main question is that whether I should take an existing contrib module and edit that to suit my bidding or should I create a custom module from scratch.

SCENARIO 1: Custom module is preferred

  • One of my interesting tasks has been to create a question and answer forum for a site where people can ask questions related to the site’s content and get them answered.
  • In order to implement this, I had found some contrib modules notably “questions and answer” among others. I installed it and tried it out and the basic requirement of asking questions and answering them seemed to have been satisfied by the contrib module.
  • But as the requirement specification increased, applying the nitty gritty small details to an already built system seemed more cumbersome than efficient. So, I decided to build a custom module from the scratch.
Are You Looking for Dedicated Drupal Developers?

SCENARIO 2: Contrib module was preferred

  • Another scenario is when we needed to apply a validation for a particular part in the system of a module. No problem, a quick view inside hook_node_validate() should do the trick nicely. Then again, isn’t there a module that can give me this? Yes, there is: Field validation.
  • I installed this module which comes with lots of validation rules and possibilities. The default validation was not matching the requirement, so I had to use a custom expression for that.

The “BIG” Question:

  • But was this the better thing to do? You might say yes, because people have been working on this module for a long time to perfect it, keep it secure and provide all kinds of goodies under the hood. And that it’s used on over thousands of websites.
  • However, the Field Validation module is big. It has a bunch of abilities to do things that allow you to perform all kinds of validation on fields. That may be useful when applying further validations for the future, but is it really efficient to install such a large module for a requirement that can be done by slightly tweaking the existing code.

Also Read: A Brief Comparison Between Drupal 7 and Drupal 8


Points To Ponder:

  • The argument that the contrib module will be useful in the future for applying other validations is correct. But that will only apply for a project which is just being started and not the ones have already reached a stable setup in their lifetime.
  • We can also argue that your custom code is not foolproof, is very hard to maintain, can be insecure if you make mistakes and will on the whole represent an unchangeable feature/bug on your site. These can all be true, but can also all can be false depending on the developer, how they document code and how they go about doing the things.
  • I ended up doing the first requirement as a custom module, which would have required overhauling the whole “question and answer” contrib module otherwise and thus lead to unwanted errors and vulnerabilities.
  • For the second, I chose to use the “field validation” module. It was a rather young site. Even though deployed, had a lot of stuff that had to be developed in it and the module would be pretty useful in the foresight.

Conclusion:

We are not here to review the contrib modules, but whether or not installing any contrib module for a particular purpose is the right thing to do or not. This is mostly a Drupal 7 problem as in D8 we use object oriented practices by which we can have as much code as we want because we only load the necessary parts when needed.

So, that was my set of arguments in the matter. What do you think? Is there any thumb rule that you follow when it comes to using contrib module? Do let me know, as there is no one true answer.

Contributed By:

Anand Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge