You are here

Example: Field Types API in Examples for Developers 8

Same name and namespace in other branches
  1. 7 field_example/field_example.module \field_example
  2. 3.x modules/field_example/field_example.module \field_example

Examples using Field Types API.

Providing a field requires:

  • Defining an entity field item. Entity field items are typed data objects containing the field values.

  • Defining a field type schema at config/schema/[module_name].schema.yml
    • config/schema/field_example.schema.yml
  • One or more widgets specifying how the field appears in edit forms
    • Drupal\field_example\Plugin\Field\TextWidget
    • Drupal\field_example\Plugin\Field\Text3Widget
    • Drupal\field_example\Plugin\Field\ColorPickerWidgetWidget
  • One or more formatters specifying how the field appears in displayed entities

    • Drupal\field_example\Plugin\FieldFormatter\SimpleTextFormatter
    • Drupal\field_example\Plugin\FieldFormatter\ColorBackgroundFormatter

End of "defgroup field_example".

See also

Field Types API

Field API

Schema API

Parent topics

File

field_example/field_example.module, line 8
An example field using the Field Types API.

Classes

Namesort descending Location Description
ColorBackgroundFormatterTest field_example/tests/src/Functional/ColorBackgroundFormatterTest.php Test the basic functionality of Color background formatter.
ColorPickerWidgetTest field_example/tests/src/Functional/ColorPickerWidgetTest.php Test the basic functionality of Color Picker Widget.
FieldExampleMenuTest field_example/tests/src/Functional/FieldExampleMenuTest.php Test the user-facing menus in Field Example.
TextWidgetTest field_example/tests/src/Functional/TextWidgetTest.php Test basic functionality of the widgets.