Leveraging core Drupal APIs to build a custom application

Speaker(s)
gease
Session track
Code & Development
Experience level
Intermediate
Duration
50 min

Drupal 8 came with great changes in core APIs, though it kept vocabulary (eg fields, entities) and user experience essentially the same. New structure of core APIs provide great flexibility and power in building custom applications, deviating from standard Drupal content-publishing logic.

Core Drupal operates some variety of fields (like text, files, entity references) and entities (in first place nodes, then blocks, comments, taxonomies etc), which imply some logic of content input, handling and representation. Everyone is pretty familiar with, eg, Drupal text or file input widgets, choice between single- and multi-valued fields, node output as a collection of fields, etc, and can hardly imagine that logic of data input and representation can be different. But in the real word this logic can be quite different and its variants are limitless. The most common examples of data that cannot be matched with Drupal core fields and entities are commerce-related stuff (such as products, prices, transactions, shippings etc) and spacial data, where coordinates, addresses and maps relate to each other in their particular way.

In the session, I'm going to talk how I was building a custom math learning app. The idea is very simple - there's a series of numbers that the user needs to add or subtract. But combined with the ability to set up lessons, display these math problems in different way, track the progress of users etc this forms a challenging task obviously not fitting the Drupal core landscape of fields and entities.

So I will decompose Drupal APIs responsible for implementing data storage and implementation logic, and show how to build some custom implementation from the ground up. This will involve creating custom data type with TypedData API, with its validators, building custom fields based on these data types, create field widgets (including overriding core Drupal single- and multiple-value logic) and field formatters (that use jQuery scenarios), build entities with custom validation, presentation and access logic. This will imply understanding and using a handful of plugins (DataType, FieldType, FieldFormatter, FieldWidget, ContentEntityType, ConfigEntityType, to name the most important), extending a number of classes, creating controllers, routes and templates. There will be a lot of code examples, and by the end of the session the audience should have a much better idea how to build a custom Drupal-based application.