Creating a custom field widget
Field widgets provide the form component to a field in an entity form. These integrate with the Form API to define how a field can be edited and the way in which the data can be formatted before it is saved. Field widgets are chosen and customized through the form display interface.
In this recipe, we will create a widget for the field created in the Creating a custom field type recipe in this chapter. The field widget will provide two text fields for entering the first and last name items.
Getting ready
This recipe provides a field widget 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/FieldWidget
directory in the module’s directory. TheField
module discovers field widgets in thePlugin\Field\FieldWidget
namespace:mkdir -p src/Plugin/Field/FieldWidget
- Create a
RealNameDefaultWidget.php
file in the newly created directory...