Field formatter
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 the preferred output. So, let's do it then.
Field formatters go inside the Plugin/Field/FieldFormatter
namespace of our module, so let's go ahead and create our own:
namespace Drupal\license_plate\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FormatterBase...