Summary

In this chapter, we took on the client-side and talked about JavaScript and client-side capabilities in Drupal 8. We started with the approach we need to take when writing JavaScript in a Drupal context. We learned about behaviors, why they are important, and how to use them. We also saw how we can pass around data from the server (Drupal) to the client-side and make use of it in JavaScript.

Funnily enough, we then switched to a no-JavaScript-allowed policy for the rest of the chapter. We did this to prove how powerful the Drupal Ajax API is, with which we can perform complex server-to-client interactions even if we are not frontend developers that can write JavaScript code. And to demonstrate the API, we first looked at how simple links can be turned into Ajax requests. We followed that up with an important refactor of our earlier product importer functionality which relied on Ajax to make the Importer configuration entity form dynamic (dependent on the selected plugin). Let's not forget another nugget of information—dynamic configuration schema—which allows us to decouple the configuration entity data definitions from that of their selected plugins.

Finally, we finished by looking at the States system of the Form API which allows us to declaratively code client-side manipulations onto our form elements, essentially making them dependent on the user's interaction with the form.

In the next chapter, we are going to talk about internationalization and translations to make sure our applications can be used anywhere around the globe.