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

 
4 tính năng Timeline bạn nên biết

4 tính năng Timeline bạn nên biết

Mặc dù không quá nổi bật nhưng những tính năng này rất đáng chú ý, giúp bạn quản lí chặt chẽ hơn trang Timeline lung linh của mình.

Quy trình SEO mới hiệu quả năm 2013

Quy trình SEO mới hiệu quả năm 2013

Để làm SEO hiệu quả, thì ít nhất, bạn phải tỏ ra là một nhà chiến lược số hóa, một chuyên gia tiếp thị trên các mạng xã hội, một tay chuyên viết lách nội dung, một người chuyên tối ưu hóa tỉ lệ chuyển đổi cho website, và một chuyên gia về PR.

Vấn đề cơ bản để viết ứng dụng MapReduce

Vấn đề cơ bản để viết ứng dụng MapReduce

Để viết 1 ứng dụng MapReduce chạy trên Hadoop, điều quan trọng nhất là chuẩn bị 2 hàm số Map và Reduce, tuy nhiên cũng còn nhiều thành phần khác cần phải biết. Để dễ hiểu, có thể tóm tắt đường đi của dữ liệu trong ứng dụng MapReduce như hình sau:

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

 

Diet con trung