Field Types API

Same name and namespace in other branches
  1. 7.x modules/field/field.api.php \field_types
  2. 9 core/modules/field/field.api.php \field_types
  3. 8.9.x core/modules/field/field.api.php \field_types
  4. 10 core/modules/field/field.api.php \field_types

Defines field, widget, display formatter, and storage types.

In the Field API, each field has a type, which determines what kind of data (integer, string, date, etc.) the field can hold, which settings it provides, and so on. The data type(s) accepted by a field are defined in the class implementing \Drupal\Core\Field\FieldItemInterface::schema() method.

Field types are plugins with \Drupal\Core\Field\Attribute\FieldType attributes and implement plugin interface \Drupal\Core\Field\FieldItemInterface. Field Type plugins are managed by the \Drupal\Core\Field\FieldTypePluginManager class. Field type classes usually extend base class \Drupal\Core\Field\FieldItemBase. Field-type plugins need to be in the namespace \Drupal\{your_module}\Plugin\Field\FieldType. See the Plugin API topic for more information on how to define plugins.

The Field Types API also defines two kinds of pluggable handlers: widgets and formatters. Widgets specify how the field appears in edit forms, while formatters specify how the field appears in displayed entities.

See Field API for information about the other parts of the Field API.

See also

Field API

Field Widget API

Field Formatter API

Plugin API

Parent topics


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


Title Sort descending File name Summary
hook_field_formatter_settings_summary_alter core/modules/field_ui/field_ui.api.php Alters the field formatter settings summary.
hook_field_formatter_third_party_settings_form core/modules/field_ui/field_ui.api.php Allow modules to add settings to field formatters provided by other modules.
hook_field_info_alter core/modules/field/field.api.php Perform alterations on Field API field types.
hook_field_info_entity_type_ui_definitions_alter core/modules/field/field.api.php Alters the UI field definitions.
hook_field_storage_config_update_forbid core/modules/field/field.api.php Forbid a field storage update from occurring.
hook_field_ui_preconfigured_options_alter core/modules/field/field.api.php Perform alterations on preconfigured field options.
hook_field_widget_settings_summary_alter core/modules/field_ui/field_ui.api.php Alters the field widget settings summary.
hook_field_widget_third_party_settings_form core/modules/field_ui/field_ui.api.php Allow modules to add settings to field widgets provided by other modules.


Title Sort descending File name Summary
FieldItemBase core/lib/Drupal/Core/Field/FieldItemBase.php An entity field item.
FieldType core/lib/Drupal/Core/Field/Attribute/FieldType.php Defines a FieldType attribute.
FieldType core/lib/Drupal/Core/Field/Annotation/FieldType.php Defines a FieldType annotation object.
FieldTypePluginManager core/lib/Drupal/Core/Field/FieldTypePluginManager.php Plugin manager for 'field type' plugins.


Title Sort descending File name Summary
FieldItemInterface core/lib/Drupal/Core/Field/FieldItemInterface.php Interface for entity field items.
FieldTypePluginManagerInterface core/lib/Drupal/Core/Field/FieldTypePluginManagerInterface.php Defines an interface for the field type plugin manager.

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