We Build Websites

Headless Drupal, One form at a time
By Amitai Burstein (@amitaibu) // 09 Jul 2014

  • Form API is great, but Form API is hard when you try to do fancier stuff - like wizards and other things that clients often want.
  • Angular forms are great, but Angular forms are hard too - you need to write your own custom endpoints and server side validation.

But now that RESTful integrates with Entity Validator, I would change the equation and simply say something rarely heard in the Drupal community: Forms are Fun!

This form is not Form API, it's angular!

Go ahead, try it yourself on simplyTest.me

The example module shows how all the HTML, CSS, and JS are bundled together in an Angular App, and Drupal simply ng-includes it.

The tricky part is the server side validation, which is now handled by Entity Validator module. And of course the endpoint itself is handled by RESTful which does a lot of the heavy lifting by taking care of authentication, permissions, CSRF tokens, exposing the RESTful resource etc.

Developers would appreciate the very little code needed to declare the validation and the RESTful resource.

As a benefit, since RESTful spits out structured error messages, displaying error messages inline is really simple.

captionDetailed errors are part of the JSON response
Inline errors, provide a better UX

In Gizra we already have projects where we don’t use any node form to create or edit content. Everything is implemented in a slick Angular based UI - one that users enjoy using.

Headless Drupal isn’t in the future. It’s here, and you can start using it with test-covered and OOP modules like RESTful and Zariz.