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...