Field formatter

Alright, so our field now also has a widget that users can input data with. Let's create the default field formatter to make the field whole.

Before actually coding it, let's establish what we want our formatter to look and behave like. By default, we want the license plate data to be rendered like this:

<span class="license-plate—code">{{ code }}</span> <span class="license-plate—number">{{ number }}</span>  

So, each component is wrapped inside its own span tag, and some handy classes are applied to them. Alternatively, we may want to concatenate the two values together into one single span tag:

<span class="license-plate">{{ code }} {{ number }}</span>  

This could be a setting on the formatter, allowing the user to choose ...

Get Drupal 8 Module Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.