Example: Field Types API

Same name in other branches
  1. 3.x modules/field_example/field_example.module \field_example
  2. 7.x-1.x field_example/field_example.module \field_example
  3. 4.0.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

field

schemaapi

Parent topics

File

field_example/field_example.module, line 8

Classes

Title Sort descending File name Summary
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.