Examples using Field Types API.
This is updated from Barry Jaspan's presentation at Drupalcon Paris, Video Presentation
Providing a field requires:
- Defining a field:
- hook_field_info()
- hook_field_schema()
- hook_field_validate()
- hook_field_is_empty()
- Defining a formatter for the field (the portion that outputs the field for
display):
- hook_field_formatter_info()
- hook_field_formatter_view()
- Defining a widget for the edit form:
- hook_field_widget_info()
- hook_field_widget_form()
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
| Name | Description |
|---|---|
| field_example_3text_validate | Validate the individual fields and then convert them into a single HTML RGB value as text. |
| field_example_field_formatter_info | Implements hook_field_formatter_info(). |
| field_example_field_formatter_view | Implements hook_field_formatter_view(). |
| field_example_field_info | Implements hook_field_info(). |
| field_example_field_is_empty | Implements hook_field_is_empty(). |
| field_example_field_schema | Implements hook_field_schema(). |
| field_example_field_validate | Implements hook_field_validate(). |
| field_example_field_widget_error | Implements hook_field_widget_error(). |
| field_example_field_widget_form | Implements hook_field_widget_form(). |
| field_example_field_widget_info | Implements hook_field_widget_info(). |
| field_example_menu | Implements hook_menu(). |
| _field_example_page | A simple page to explain to the developer what to do. |
File
- field_example/
field_example.module, line 7 - An example field using the Field Types API.