{"id":2893,"date":"2019-04-29T18:49:21","date_gmt":"2019-04-29T13:19:21","guid":{"rendered":"https:\/\/www.idslogic.com\/blog\/?p=2893"},"modified":"2025-02-25T11:04:03","modified_gmt":"2025-02-25T05:34:03","slug":"drupal-modules-custom-or-contrib","status":"publish","type":"post","link":"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib","title":{"rendered":"Drupal Module Development :  Custom or Contributed?"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_72 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\/#INTRODUCTION\" title=\"INTRODUCTION:\">INTRODUCTION:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\/#SCENARIO_1_Custom_module_is_preferred\" title=\"SCENARIO 1: Custom module is preferred\">SCENARIO 1: Custom module is preferred<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\/#SCENARIO_2_Contrib_module_was_preferred\" title=\"SCENARIO 2: Contrib module was preferred\">SCENARIO 2: Contrib module was preferred<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\/#The_%E2%80%9CBIG%E2%80%9D_Question\" title=\"The \u201cBIG\u201d Question:\">The \u201cBIG\u201d Question:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\/#Points_To_Ponder\" title=\"Points To Ponder:\">Points To Ponder:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\/#Conclusion\" title=\"Conclusion:\">Conclusion:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\/#Sign_up_our_Newsletter\" title=\"Sign up our Newsletter!\">Sign up our Newsletter!<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"INTRODUCTION\"><\/span><span style=\"font-size: 18pt; color: #008000;\"><strong>INTRODUCTION: <\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-size: 14pt;\">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.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"SCENARIO_1_Custom_module_is_preferred\"><\/span><span style=\"font-size: 18pt; color: #008080;\"><strong>SCENARIO 1: Custom module is preferred<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul style=\"list-style-type: square;\">\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">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&#8217;s content and get them answered.<\/span><\/span><\/li>\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">In order to implement this, I had found some contrib modules notably &#8220;questions and answer&#8221; 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.<\/span><\/span><\/li>\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">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.<br \/>\n<\/span><\/span><\/li>\n<\/ul>\n<div id=\"es_shortcode_msg\" class=\"es_msg\"><\/div>\n<div style=\"margin: 40px auto; border: 2px solid #f46f25; padding: 20px 25px; border-radius: 6px; background: 0;\">\n<div style=\"display: inline-block; vertical-align: middle; width: 62%;\"><span style=\"font-size: 14pt;\"><strong>Are You Looking for Dedicated Drupal Developers?<\/strong><\/span><\/div>\n<div style=\"display: inline-block; vertical-align: middle; width: 36%;\"><span style=\"font-size: 14pt;\"><a style=\"padding: 10px 22px; margin-bottom: 0; line-height: 1.3em; text-align: center; text-decoration: none; vertical-align: middle; cursor: pointer; color: #ffffff; background-color: #f46f25; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; display: block;\" href=\"https:\/\/www.idslogic.com\/dedicated-drupal-developer\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hire Dedicated Drupal Developer!<\/a><\/span><\/div>\n<\/div>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"SCENARIO_2_Contrib_module_was_preferred\"><\/span><span style=\"font-size: 18pt; color: #008080;\"><strong>SCENARIO 2: Contrib module was preferred<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul style=\"list-style-type: square;\">\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">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&#8217;t there a module that can give me this? Yes, there is: Field validation.<\/span><\/span><\/li>\n<li><span style=\"font-size: 14pt;\">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.<\/span><\/li>\n<\/ul>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"The_%E2%80%9CBIG%E2%80%9D_Question\"><\/span><span style=\"font-size: 18pt; color: #008000;\"><strong>The \u201cBIG\u201d Question:<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul style=\"list-style-type: square;\">\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">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&#8217;s used on over thousands of websites.<\/span><\/span><\/li>\n<li><span style=\"font-size: 14pt;\">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.<\/span><\/li>\n<\/ul>\n<blockquote>\n<p style=\"box-shadow: 0 0 16px #cccccc; padding: 10px;\"><span style=\"font-size: 18.6667px;\"><b><span style=\"color: #800000;\">Also Read:<\/span>\u00a0<\/b><a href=\"\/blog\/a-brief-comparison-between-drupal-7-and-drupal-8\"><span style=\"color: #ff0000;\">A Brief Comparison Between Drupal 7 and Drupal 8<\/span><\/a><\/span><\/p>\n<\/blockquote>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"Points_To_Ponder\"><\/span><span style=\"font-size: 18pt; color: #008000;\"><strong>Points To Ponder:<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul style=\"list-style-type: square;\">\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">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.<\/span><\/span><\/li>\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">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.<\/span><\/span><\/li>\n<li><span style=\"font-size: 14pt;\"><span style=\"font-size: 14pt;\">I ended up doing the first requirement as a custom module, which would have required overhauling the whole &#8220;question and answer&#8221; contrib module otherwise and thus lead to unwanted errors and vulnerabilities.<\/span><\/span><\/li>\n<li><span style=\"font-size: 14pt;\">For the second, I chose to use the &#8220;field validation&#8221; 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.<\/span><\/li>\n<\/ul>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><span style=\"font-size: 18pt; color: #800000;\"><strong>Conclusion:<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-size: 14pt;\">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. <\/span><\/p>\n<p><span style=\"font-size: 14pt;\">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.<\/span><\/p>\n<p><span style=\"color: #800000;\"><strong><span style=\"font-size: 14pt;\">Contributed By:<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Anand Kumar<\/span><\/p>\n<div class=\"newsletter_form\">\n<h2><span class=\"ez-toc-section\" id=\"Sign_up_our_Newsletter\"><\/span>Sign up our Newsletter!<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"emaillist\" id=\"es_form_f0-n1\"><form action=\"\/blog\/wp-json\/wp\/v2\/posts\/2893#es_form_f0-n1\" method=\"post\" class=\"es_subscription_form es_shortcode_form  es_ajax_subscription_form\" id=\"es_subscription_form_6a54665db936a\" data-source=\"ig-es\" data-form-id=\"0\"><div class=\"es-field-wrap\"><label>Name<br \/><input type=\"text\" name=\"esfpx_name\" class=\"ig_es_form_field_name\" placeholder=\"\" value=\"\" \/><\/label><\/div><div class=\"es-field-wrap\"><label>Email*<br \/><input class=\"es_required_field es_txt_email ig_es_form_field_email\" type=\"email\" name=\"esfpx_email\" value=\"\" placeholder=\"\" required=\"required\" \/><\/label><\/div><input type=\"hidden\" name=\"esfpx_form_id\" value=\"0\" \/><input type=\"hidden\" name=\"es\" value=\"subscribe\" \/>\n\t\t\t<input type=\"hidden\" name=\"esfpx_es_form_identifier\" value=\"f0-n1\" \/>\n\t\t\t<input type=\"hidden\" name=\"esfpx_es_email_page\" value=\"2893\" \/>\n\t\t\t<input type=\"hidden\" name=\"esfpx_es_email_page_url\" value=\"https:\/\/www.idslogic.com\/blog\/drupal-modules-custom-or-contrib\" \/>\n\t\t\t<input type=\"hidden\" name=\"esfpx_status\" value=\"Unconfirmed\" \/>\n\t\t\t<input type=\"hidden\" name=\"esfpx_es-subscribe\" id=\"es-subscribe-6a54665db936a\" value=\"15c9239884\" \/>\n\t\t\t<label style=\"position:absolute;top:-99999px;left:-99999px;z-index:-99;\" aria-hidden=\"true\"><span hidden>Please leave this field empty.<\/span><input type=\"email\" name=\"esfpx_es_hp_email\" class=\"es_required_field\" tabindex=\"-1\" autocomplete=\"-1\" value=\"\" \/><\/label><input type=\"submit\" name=\"submit\" class=\"es_subscription_form_submit es_submit_button es_textbox_button\" id=\"es_subscription_form_submit_6a54665db936a\" value=\"Subscribe\" \/><span class=\"es_spinner_image\" id=\"spinner-image\"><img decoding=\"async\" src=\"https:\/\/www.idslogic.com\/blog\/wp-content\/plugins\/email-subscribers\/lite\/public\/images\/spinner.gif\" alt=\"Loading\" \/><\/span><\/form><span class=\"es_subscription_message \" id=\"es_subscription_message_6a54665db936a\" role=\"alert\" aria-live=\"assertive\"><\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2894,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256],"tags":[816,815,814,813],"class_list":["post-2893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cms","tag-drupal-contributed-module","tag-drupal-custom-module","tag-drupal-module","tag-drupal-module-development"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts\/2893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/comments?post=2893"}],"version-history":[{"count":5,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts\/2893\/revisions"}],"predecessor-version":[{"id":10713,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts\/2893\/revisions\/10713"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/media\/2894"}],"wp:attachment":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/media?parent=2893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/categories?post=2893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/tags?post=2893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}