Field Widget API

Same name in other branches
  1. 7.x modules/field/field.api.php \field_widget
  2. 9 core/modules/field/field.api.php \field_widget
  3. 10 core/modules/field/field.api.php \field_widget
  4. 11.x core/modules/field/field.api.php \field_widget

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 annotated with class \Drupal\Core\Field\Annotation\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 API

Field Types API

Field Formatter API

Plugin API

Parent topics

File

core/modules/field/field.api.php, line 123

Functions

Title Sort descending File name Summary
hook_field_widget_form_alter core/modules/field/field.api.php Alter forms for field widgets provided by other modules.
hook_field_widget_info_alter core/modules/field/field.api.php Perform alterations on Field API widget types.
hook_field_widget_multivalue_form_alter core/modules/field/field.api.php Alter forms for multi-value field widgets provided by other modules.
hook_field_widget_multivalue_WIDGET_TYPE_form_alter core/modules/field/field.api.php Alter multi-value widget forms for a widget provided by another module.
hook_field_widget_WIDGET_TYPE_form_alter core/modules/field/field.api.php Alter widget forms for a specific widget provided by another module.

Classes

Title Sort descending File name Summary
FieldWidget core/lib/Drupal/Core/Field/Annotation/FieldWidget.php Defines a FieldWidget annotation object.
WidgetBase core/lib/Drupal/Core/Field/WidgetBase.php Base class for 'Field widget' plugin implementations.
WidgetPluginManager core/lib/Drupal/Core/Field/WidgetPluginManager.php Plugin type manager for field widgets.

Interfaces

Title Sort descending File name Summary
WidgetInterface core/lib/Drupal/Core/Field/WidgetInterface.php Interface definition for field widget plugins.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.