/
hook_options_list.sublime-snippet
51 lines (50 loc) · 1.27 KB
/
hook_options_list.sublime-snippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<snippet>
<tabTrigger>hook_options_list</tabTrigger>
<content><![CDATA[/**
* Implements hook_options_list().
*/
function ${TM_FILENAME/([^.]*)\..*$/$1/}_options_list(\$field) {
// Sample structure.
/*
*\$options = array(
* 0 => t('Zero'),
* 1 => t('One'),
* 2 => t('Two'),
* 3 => t('Three'),
*);
*/
// Sample structure with groups. Only one level of nesting is allowed. This
// is only supported by the 'options_select' widget. Other widgets will
// flatten the array.
/*
*\$options = array(
* t('First group') => array(
* 0 => t('Zero'),
* ),
* t('Second group') => array(
* 1 => t('One'),
* 2 => t('Two'),
* ),
* 3 => t('Three'),
*);
*/
// In actual implementations, the array of options will most probably depend
// on properties of the field. Example from taxonomy.module:
/*
*\$options = array();
*foreach (\$field['settings']['allowed_values'] as \$tree) {
* \$terms = taxonomy_get_tree(\$tree['vid'], \$tree['parent']);
* if (\$terms) {
* foreach (\$terms as \$term) {
* \$options[\$term->tid] = str_repeat('-', \$term->depth) . \$term->name;
* }
* }
*}
*/
\$options = array(
${1} => ${2},
);
return \$options;
}
]]></content>
</snippet>