Creating a custom field formatter
Field formatters define the way in which a field type will be presented. These formatters return the render array information to be processed by the theming layer. Field formatters are configured on the display mode interfaces.
In this recipe, we will create a formatter for the field created in the Creating a custom field type recipe in this chapter. The field formatter will display the first and last name values inline, as a full name.
Getting ready
This recipe provides a field formatter for the field type created in the previous recipe, Creating a custom field type.
How to do it…
- First, we need to create the
src/Plugin/Field/FieldFormatter
directory in the module’s directory. TheField
module discovers field formatters in thePlugin\Field\FieldFormatter
namespace:mkdir -p src/Plugin/Field/FieldFormatter
- Create a
RealNameFormatter.php
file in the newly created directory so that we can define theRealNameFormatter...