Declare information about a widget, including indicating how the default and multiple values for the widget will be handled.

Return value

An array keyed by widget name. Each element of the array is an associative array with these keys and values:

  • "label": The human-readable label for the widget.
  • "field types": An array of field type names that can be edited using this widget.
  • "multiple values": Either
    • CONTENT_HANDLE_CORE (default value) or
    • CONTENT_HANDLE_MODULE.

    By default, the content module handles multiple values. Change this value only if you intend to handle multiple values in your module code. If you do change this value then multiple items will be passed to your widget's theme function in the $item array.

  • "callbacks": An array of callbacks. To set the default value, set the value of "default value" to one of the following values:
    • CONTENT_CALLBACK_DEFAULT (default value),
    • CONTENT_CALLBACK_CUSTOM, or
    • CONTENT_CALLBACK_NONE

Multiple values and callbacks can be omitted if default handling is used. They're included in the code example below just so this module can be used as an example for custom modules that might do things differently.

/**
* Implementation of hook_widget_info().
*/
function text_widget_info() {
  return array(
    'text_textfield' => array(
      'label' => 'Text Field',
      'field types' => array('text'),
      'multiple values' => CONTENT_HANDLE_CORE,
      'callbacks' => array(
        'default value' => CONTENT_CALLBACK_DEFAULT,
        ),
    ),
    'text_textarea' => array(
      'label' => 'Text Area',
      'field types' => array('text'),
      'multiple values' => CONTENT_HANDLE_CORE,
      'callbacks' => array(
        'default value' => CONTENT_CALLBACK_DEFAULT,
        ),
    ),
  );
}

Comments

pschopf’s picture

It seems that if you are creating a new field type, it is common to add a hook_widget_info() function. If you do this, the 'field types' element of the array should point to the new field type itself. I am suspicious of these "self-referential" coding practices, and thought that the 'field type' was making reference to the underlying database storage type. For now, my xxx.module declares function xxx_widget_info() with 'field types' => array('xxx'),

nevets’s picture

'field_types' actually comes from any type defined in an implementation of hook_field_info(). It defined what types the widget can be used with.

wildpeaks’s picture

Note that the ID of widgets ("'text_textfield" and "text_textarea" in the example snipplet) are 32chars strings, so any name longuer than that will be trimmed without warning.