Skip to content

Field Widget API

Define Field API widget types.

Field API widgets specify how fields are displayed in edit forms. Fields of a given field type may be edited using more than one widget. In this case, the Field UI module allows the site builder to choose which widget to use.

Widgets are Plugins managed by the \Drupal\Core\Field\WidgetPluginManager class. A widget is a plugin attributed with class \Drupal\Core\Field\Attribute\FieldWidget that implements \Drupal\Core\Field\WidgetInterface (in most cases, by subclassing \Drupal\Core\Field\WidgetBase). Widget plugins need to be in the namespace \Drupal\{your_module}\Plugin\Field\FieldWidget.

Widgets are Form API elements with additional processing capabilities. The methods of the WidgetInterface object are typically called by respective methods in the \Drupal\Core\Entity\Entity\EntityFormDisplay class.

See also

field

Field Types API

Field Formatter API

Plugin API

Parent topics

Hooks