Field widgets provide the form interface to edit a field. 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.
Create a new module, such as the one from the Creating a custom field type recipe. We will refer to the module as mymodule
throughout the recipe. Use your module's appropriate name.
- We will need to create the
src/Plugin/Field/FieldWidget
directory in the module's base location. TheField
module discovers field widgets in thePlugin\Field\FieldWidget
namespace. - Create a
RealNameDefaultWidget.php
file in the newly created directory so that we can define theRealNameDefaultWidget...