• Deutsch
  • English

Working on Drupal 8's entity validation API

tl;dr: I'm going to work on Drupal 8's entity validation system for the next two months with the goal to create a consistent API for entities and fields. Not only forms will be able to trigger validation constraints but also incoming data from web service interfaces, migration processes or any other code that wishes to execute the validation.

I'm glad that I got funding again to professionally work on Drupal 8 core. Big thanks to Acquia and my employer epiqo who are sponsoring this effort, similar to my REST module work earlier this year.

What are you talking about?

Consider the maximum length of a node title in Drupal. In Drupal 7 we specify a #maxlength of 255 for the title in the node edit form (note that we also specify the database definition of the title field length, but we cannot process database errors in a meaningful way for validation). Now the validation of the title field is completely tied to the form API, a web service module cannot easily reuse that validation information when it receives a data submission. The situation gets even more complicated if form validation callbacks are needed that perform some computation (example: the node title should be unique, which requires a database lookup). The entity system has no information what validators are registered with the form API and cannot provide that to the web service module. And reverse engineering some deeply nested form arrays and creating pseudo form states is not a solution to the problem that an API is missing here.

In Drupal 8 we are going to change that: Symfony validators to the rescue! We have now an architecture in place that allows us to retrieve validation constraint violations for individual fields and whole entities. Read up on that in the documentation.

Tasks

I will tackle the conversion of all Drupal core entity forms and validators, so that we leverage the full potential of our brand new validation API. I will also look into a generic implementation for all entity forms and how that aligns with configurable fields and entity base fields. Once that is completed I will integrate the entity validation into REST module, so that it can verify all incoming data same as a usual form submission would do.

Time frame

Drupal 8 is now at API freeze which means we need to be careful what we are going to change. I hope that we can keep API breaking changes to a minimum for entity validation, since we already have the concepts ready to use I'm optimistic. I'm dedicated to work on this for the next two months, so the goal is to finish off all validation implementation details until the beginning of September.

Your help with all the validation issues is appreciated, I'm not going to succeed on my own here, feel free to jump in! Special thanks to Wolfgang Ziegler (fago) and all other contributors who made this entity validation API possible. Let's finish this!

Feedback