Creating custom fields using Drupal 7 field api
** Work in progress **
This article describes which Drupal 7 field api hooks one must implement to create fully functional custom field. This field then may be usable on any fieldable object in Drupal 7.
// tells drupal which field(s) your module defines and implements
function hook_field_info() {}
// tells drupal which widgets your module defines and implements
// these widgets may be made available to other fields defined elsewhere (ex, core fields). but for our purpose i will describe how this hook interacts with hook_field_info()
function hook_field_widget_info() {}
// This hook defines the field schema. this is necessary because it tells drupal what columns to create in database where field's data will be stored. @todo: Find out whether custom table must be created or whether field_sql storage takes care of this completely.
function hook_field_schema($field) {}
// This tells drupal what formatters your module defines and implements as well as which fields this formatter is restricted to. this is only registry type hook, actual definition of formatters happens in hook_field_formatter_view.
function hook_field_formatter_info() {}
// This hook exposes settings that you users typically see on field edit page (ex: admin/structure/types/manage/%node_type/fields/%field_name
function hook_field_settings_form($field, $instance, $has_data) {}
// This hook defines field form. This is displayed on node form allowing users enter data.
function hook_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {}
// This seem to be mandatory. During form submit this function tells drupal whether the data submitted is considered empty or not. For example link field consist of link text and link URI. If text is entered without URI we should consider the field empty because text without link is useless.
function hook_field_is_empty($item, $field) {}
// This implements each formatter registered by this module inside hook_field_formatter_info(). this gets called during node view and this function is responsible returning renderable array that represents field's data.
function hook_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display) {}
- 492 reads
No responses to "Creating custom fields using Drupal 7 field api"
Post new comment