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.
- $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.