Example: Field Types API

  1. drupal
    1. 8
    2. 7

Examples using Field Types API.

This is updated from Barry Jaspan's presentation at Drupalcon Paris, Video Presentation

Providing a field requires:

Our module defines the field in field_example_field_info(), field_example_field_validate() and field_example_field_is_empty(). field_example_field_schema() is implemented in field_example.install.

Our module sets up a formatter in field_example_field_formatter_info() and field_example_field_formatter_view(). These are the API hooks that present formatted and themed output to the user.

And finally, our module defines the widet in field_example_field_widget_info() and field_example_field_widget_form(). The widget is the form element used to receive input from the user when the field is being populated.

See also

field_types

field

Functions & methods

NameDescription
field_example_3text_validateValidate the individual fields and then convert them into a single HTML RGB value as text.
field_example_field_formatter_infoImplements hook_field_formatter_info().
field_example_field_formatter_viewImplements hook_field_formatter_view().
field_example_field_infoImplements hook_field_info().
field_example_field_is_emptyImplements hook_field_is_empty().
field_example_field_schemaImplements hook_field_schema().
field_example_field_validateImplements hook_field_validate().
field_example_field_widget_errorImplements hook_field_widget_error().
field_example_field_widget_formImplements hook_field_widget_form().
field_example_field_widget_infoImplements hook_field_widget_info().
field_example_menuImplements hook_menu().
_field_example_pageA simple page to explain to the developer what to do.

examples/field_example/field_example.module, line 7