-
Notifications
You must be signed in to change notification settings - Fork 2
/
combo.install
101 lines (99 loc) · 2.54 KB
/
combo.install
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Implements hook_install().
*/
function combo_install() {
$types = array(
// A node type that will contain the combo field.
array(
'type' => 'test_combo',
'name' => 'Test combo field',
'base' => 'node_content',
'description' => '',
'custom' => 1,
'modified' => 1,
'locked' => 0,
),
// A node type receiving the values of the combo field (= the X-entity).
array(
'type' => 'combo_value',
'name' => 'Combo-field value',
'base' => 'node_content',
'description' => '',
'custom' => 1,
'modified' => 1,
'locked' => 0,
),
);
foreach ($types as $type) {
$type = node_type_set_defaults($type);
node_type_save($type);
}
$fields = array(
// The fields in the combo.
array(
'field_name' => 'field_combo_1',
'type' => 'number_integer',
),
array(
'field_name' => 'field_combo_2',
'type' => 'number_integer',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
),
array(
'field_name' => 'field_combo_3',
'type' => 'file',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
),
// The combo field.
array(
'field_name' => 'field_combo',
'type' => 'combo',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
),
// A regular field.
array(
'field_name' => 'field_basic',
'type' => 'number_integer',
),
);
$instances = array(
// Attach the two fields in the combo to the 'combo_value' node type.
array(
'field_name' => 'field_combo_1',
'entity_type' => 'node',
'bundle' => 'combo_value',
'settings' => array('min' => 0, 'max' => 5),
),
array(
'field_name' => 'field_combo_2',
'entity_type' => 'node',
'bundle' => 'combo_value',
'settings' => array('min' => 0, 'max' => 5),
),
array(
'field_name' => 'field_combo_3',
'entity_type' => 'node',
'bundle' => 'combo_value',
'settings' => array('file_extensions' => 'txt png gif jpg jpeg'),
),
// Attach the combo-field and a regular number field to the 'test' node type.
array(
'field_name' => 'field_combo',
'entity_type' => 'node',
'bundle' => 'test_combo',
),
array(
'field_name' => 'field_basic',
'entity_type' => 'node',
'bundle' => 'test_combo',
'settings' => array('min' => 0, 'max' => 5),
),
);
foreach ($fields as $field) {
field_create_field($field);
}
foreach ($instances as $instance) {
field_create_instance($instance);
}
}