0934dc8d9c8dc94fcc30a994fd0987048d8fed86
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / options_list.twig
1 /**
2  * Implements hook_options_list().
3  */
4 function {{ machine_name }}_options_list($field, $instance, $entity_type, $entity) {
5   // Sample structure.
6   $options = array(
7     0 => t('Zero'),
8     1 => t('One'),
9     2 => t('Two'),
10     3 => t('Three'),
11   );
12
13   // Sample structure with groups. Only one level of nesting is allowed. This
14   // is only supported by the 'options_select' widget. Other widgets will
15   // flatten the array.
16   $options = array(
17     t('First group') => array(
18       0 => t('Zero'),
19     ),
20     t('Second group') => array(
21       1 => t('One'),
22       2 => t('Two'),
23     ),
24     3 => t('Three'),
25   );
26
27   // In actual implementations, the array of options will most probably depend
28   // on properties of the field. Example from taxonomy.module:
29   $options = array();
30   foreach ($field['settings']['allowed_values'] as $tree) {
31     $terms = taxonomy_get_tree($tree['vid'], $tree['parent']);
32     if ($terms) {
33       foreach ($terms as $term) {
34         $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
35       }
36     }
37   }
38
39   return $options;
40 }