Last updated June 17, 2013. Created by mariagwyn on May 24, 2013.
Edited by LeeHunter. Log in to edit this page.

In Drupal 8 and later, the Options module is included in Drupal core. When enabled, the Options module defines selection, check box and radio button widgets for text and numeric fields.

Options provides a number of hooks:

hook_options_list returns the list of options to be displayed for a field. Field types willing to enable one or several of the widgets defined in options.module (select, radios/checkboxes, on/off checkbox) need to
implement this hook to specify the list of options to display in the widgets.

Parameters

  • $field: The field definition.
  • $instance: The instance definition. It is recommended to only use instance level properties to filter out values from a list defined by field level properties.
  • $entity: The entity object the field is attached to.
  • @return: The array of options for the field. Array keys are the values to be stored, and should be of the data type (string, number...) expected by the first 'column' for the field type. Array values are the labels to display within the widgets. The labels should NOT be sanitized, options.module takes care of sanitation according to the needs of each widget. The HTML tags defined in _field_filter_xss_allowed_tags() are allowed, other tags will be filtered.

hook_options_list_alter alters the list of options to be displayed for a field. This hook can notably be used to change the label of the empty option.
Parameters

  • $options: The array of options for the field, as returned by hook_options_list(). An empty option (_none) might have been added, depending on the field properties.
  • $context: An associative array containing:
    • field: The field definition (\Drupal\field\Plugin\Core\Entity\Field).
    • instance: The instance definition. It is recommended to only use instance level properties to filter out values from a list defined by field level properties (Drupal\field\Plugin\Core\Entity\FieldInstance).
    • entity: The entity object the field is attached to (\Drupal\Core\Entity\EntityInterface).

Dependencies

  • Field
  • Text
  • Number

Issue Queue for 8.x
http://drupal.org/project/issues/drupal?version=8.x&component=options.mo...

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.