This example demonstrates how to use the field types API.

This has been updated from Barry Jaspan's presentation at DrupalCon Paris 2009.

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.

Finally, our module defines the widget in field_example_field_widget_info() and field_example_field_widget_form(). The widget is the form element used to receive input from users when the field is populated.

See also

Field Types API

Field API

Parent topics

File

modules/examples/field_example/field_example.module, line 7
Hook implementations for the Field Example module.

Functions

Name Locationsort descending Description
field_example_field_schema modules/examples/field_example/field_example.install Implements hook_field_schema().
field_example_field_info modules/examples/field_example/field_example.module Implements hook_field_info().
field_example_field_validate modules/examples/field_example/field_example.module Implements hook_field_validate().
field_example_field_is_empty modules/examples/field_example/field_example.module Implements hook_field_is_empty().
field_example_field_formatter_info modules/examples/field_example/field_example.module Implements hook_field_formatter_info().
field_example_field_formatter_view modules/examples/field_example/field_example.module Implements hook_field_formatter_view().
field_example_field_widget_info modules/examples/field_example/field_example.module Implements hook_field_widget_info().
field_example_field_widget_form modules/examples/field_example/field_example.module Implements hook_field_widget_form().
field_example_3text_validate modules/examples/field_example/field_example.module Validate the individual fields and then convert to RGB string.
field_example_field_widget_error modules/examples/field_example/field_example.module Implements hook_field_widget_error().
field_example_menu modules/examples/field_example/field_example.module Implements hook_menu().
_field_example_page modules/examples/field_example/field_example.module A simple page to explain to the developer what to do.

Classes

Name Locationsort descending Description
FieldExampleTest modules/examples/field_example/tests/field_example.test Functional tests for the Field Example module.