New! Drupal 9: Using Validation Constrai ...

New! Drupal 9: Using Validation Constraints To Provide Custom Field Validations

Sep 25, 2022

Client requirements can be complex and those complex requirements often require custom code to be written. This includes making sure that the editing process conforms to certain validations.

Drupal can easily handle simple validation like having a value in the field or making sure an email is valid, but with more complex validations usually require custom code.

Whilst it is possible to inject custom validators into form submissions, I find using validation constraint classes makes the whole process much more predicable. Also, validation constraints are applied at a lower level than form validations, which means we can validate the data is correct even if we are creating the entity from an API.

In this article I will look at creating a custom validation constraint that can be used on a field to provide custom validation for certain fields. We will also look at how we can use unit testing to ensure these custom validation constraint classes do what we expect them to do.

Read more here: https://www.hashbangcode.com/article/drupal-9-using-validation-constraints-provide-custom-field-validations

Enjoy this post?

Buy !# code (Hash Bang Code) a coffee

More from !# code (Hash Bang Code)