5 * Hooks provided by the Options module.
9 * Returns the list of options to be displayed for a field.
11 * Field types willing to enable one or several of the widgets defined in
12 * options.module (select, radios/checkboxes, on/off checkbox) need to
13 * implement this hook to specify the list of options to display in the
17 * The field definition.
19 * (optional) The instance definition. The hook might be called without an
20 * $instance parameter in contexts where no specific instance can be targeted.
21 * It is recommended to only use instance level properties to filter out
22 * values from a list defined by field level properties.
24 * The entity type the field is attached to.
26 * The entity object the field is attached to, or NULL if no entity
27 * exists (e.g. in field settings page).
30 * The array of options for the field. Array keys are the values to be
31 * stored, and should be of the data type (string, number...) expected by
32 * the first 'column' for the field type. Array values are the labels to
33 * display within the widgets. The labels should NOT be sanitized,
34 * options.module takes care of sanitation according to the needs of each
35 * widget. The HTML tags defined in _field_filter_xss_allowed_tags() are
36 * allowed, other tags will be filtered.
38 function hook_options_list($field, $instance, $entity_type, $entity) {
47 // Sample structure with groups. Only one level of nesting is allowed. This
48 // is only supported by the 'options_select' widget. Other widgets will
51 t('First group') => array(
54 t('Second group') => array(
61 // In actual implementations, the array of options will most probably depend
62 // on properties of the field. Example from taxonomy.module:
64 foreach ($field['settings']['allowed_values'] as $tree) {
65 $terms = taxonomy_get_tree($tree['vid'], $tree['parent']);
67 foreach ($terms as $term) {
68 $options[$term->tid
] = str_repeat('-', $term->depth
) . $term->name
;