Field widget
Let’s now create that default license plate widget plugin we referenced in the annotation of the field type, which belongs in the Plugin/Field/FieldWidget
namespace of our module:
namespace Drupal\license_plate\Plugin\Field\FieldWidget; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Field\WidgetBase; /** * Plugin implementation of the 'default_license_plate_widget' widget. * * @FieldWidget( * id = "default_license_plate_widget", * label = @Translation("Default license plate widget"), * field_types = { * "license_plate" * } * ) */ class DefaultLicensePlateWidget extends WidgetBase { use StringTranslationTrait; }
Again, we start by examining the annotation and class parents for just a bit. You will notice nothing particularly complicated, except maybe the field_types...