Bạn chọn custom module hay sử dụng contributed module

Bạn chọn custom module hay sử dụng contributed module

That is the main question. If you came here looking for a definitive answer, I'm afraid you won't find one. What you maybe will find is a discussion I propose on this topic and my two cents on the matter.

>> Hướng dẫn cho bạn Migration Drupal 6 thành Drupal 8

>> Thực hành Drupal 8 Theming Fundamentals phần 2

Why am I talking about this?

I've been working on a big Drupal website recently which has many contributed and custom modules. One of my recent tasks has been enabling validation of an existent text field used for inputting phone numbers. The client needed this number in a specific format. No problem, a quick regex inside hook_node_validate()should do the trick nicely. But then it got me thinking? Isn't there a module I can use for this instead? Well yes there is: Field validation.

I installed this module which comes with a plethora of validation rules and possibilities. The default phone validation for my country was not matching the client expectation so I had to use a custom expression for that. No problem, achieved basically the same result. But was this the better option under the circumstances? You might say yes because people have been working on this module a long time to perfect it, keep it secure and provide all sorts of goodies under the hood. Not to mention that it's used on over 10.000 websites.

However, the Field Validation module is big. It has a bunch of functionality that allows you to perform all sorts of validation on fields. This is not a bad thing, don't get me wrong. But does my little validation need warrant the installation and loading into memory of so much code? My custom solution was very targeted and took no more than 10 or so lines of code.

One argument would be that yes, because I may need other kinds of validation rules in the future so you can use this module also for those. But I think that being already very far in the lifetime of this website the odds are quite low of that. And even if this is the case, will an extra 2-3 validation needs warrant the use of this module?

On the other hand, you can argue that your custom code is not vetted, is difficult to maintain, can be insecure if you make mistakes and basically represents some non-configurable magic on your site. These can all be true but can also all be false depending on the developer, how they document code and the functionality itself.

I ended up with the custom solution in this case because on this site I really want to introduce new modules only if they bring something major to the table (performance being my concern here). So of course, the choice heavily depends on the actual module you are considering, the website it would go on and the custom code you'd write as an alternative.

Moreover, please do not focus on the actual Field Validation module in this discussion. I am not here to discuss its merits but the whether or not installing any such module that serves a tiny purpose is the right way to go. 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 what do you think? Do you have a general rule when it comes to this decision or you also take it case by case basis? If the latter, what are your criteria for informing your choice? If the former, why is this? I'd love to hear what you have to say.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Review of the Samsung Galaxy S II

Review of the Samsung Galaxy S II

The Samsung Galaxy S II is a very stylish smart phone.  From the moment I held it in my hands; I fell in love with it. It totally looks amazing.

Android 2.3 Gingerbread vượt lên dẫn đầu thị trường Android

Android 2.3 Gingerbread vượt lên dẫn đầu thị trường Android

Vào đầu tháng 10, thị phần của Android 2.3 Gingerbread chỉ chiếm khoảng 40% trong thị trường Android và xếp thứ hạng 2.

7 chiến lược tăng trưởng doanh số mảng Mỹ phẩm năm 2019

8 chiến lược tăng trưởng doanh số mảng Mỹ phẩm năm 2019

Hiện nay, xu hướng thương mại điện tử không chỉ thay đổi ngành bán lẻ mà chuyển hướng luôn ngành làm đẹp, nhất là tác động đến giới trẻ. Ngành mỹ phẩm đang chiếm doanh số lớn nhất sau ngành thời trang trên kênh thương mại điện tử.

Công ty diệt chuột T&C

 

Diet con trung