hook_field_widget_info

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 hook_field_widget_info()

Expose Field API widget types.

Widgets are Form API elements with additional processing capabilities. Widget hooks are typically called by the Field Attach API during the creation of the field form structure with field_attach_form().

Return value

An array describing the widget types implemented by the module. The keys are widget type names. To avoid name clashes, widget type names should be prefixed with the name of the module that exposes them. The values are arrays describing the widget type, with the following key/value pairs:

  • label: The human-readable name of the widget type.
  • description: A short description for the widget type.
  • field types: An array of field types the widget supports.
  • settings: An array whose keys are the names of the settings available for the widget type, and whose values are the default values for those settings.
  • behaviors: (optional) An array describing behaviors of the widget, with the following elements:

    • multiple values: One of the following constants:

      • FIELD_BEHAVIOR_DEFAULT: (default) If the widget allows the input of one single field value (most common case). The widget will be repeated for each value input.
      • FIELD_BEHAVIOR_CUSTOM: If one single copy of the widget can receive several field values. Examples: checkboxes, multiple select, comma-separated textfield.
    • default value: One of the following constants:

See also

hook_field_widget_info_alter()

hook_field_widget_form()

hook_field_widget_form_alter()

hook_field_widget_WIDGET_TYPE_form_alter()

hook_field_widget_error()

Related topics

Code

modules/field/field.api.php, line 710

<?php
function hook_field_widget_info() {
  return array(
    'text_textfield' => array(
      'label' => t('Text field'), 
      'field types' => array('text'), 
      'settings' => array('size' => 60), 
      'behaviors' => array(
        'multiple values' => FIELD_BEHAVIOR_DEFAULT, 
        'default value' => FIELD_BEHAVIOR_DEFAULT,
      ),
    ), 
    'text_textarea' => array(
      'label' => t('Text area (multiple rows)'), 
      'field types' => array('text_long'), 
      'settings' => array('rows' => 5), 
      'behaviors' => array(
        'multiple values' => FIELD_BEHAVIOR_DEFAULT, 
        'default value' => FIELD_BEHAVIOR_DEFAULT,
      ),
    ), 
    'text_textarea_with_summary' => array(
      'label' => t('Text area with a summary'), 
      'field types' => array('text_with_summary'), 
      'settings' => array(
        'rows' => 20,
        'summary_rows' => 5,
      ), 
      'behaviors' => array(
        'multiple values' => FIELD_BEHAVIOR_DEFAULT, 
        'default value' => FIELD_BEHAVIOR_DEFAULT,
      ),
    ),
  );
}
?>