-
Notifications
You must be signed in to change notification settings - Fork 7
/
zariz.install
186 lines (174 loc) · 4.88 KB
/
zariz.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* @file
* Install, update, and uninstall functions for the Zariz module.
*/
/**
* Implements hook_schema().
*/
function zariz_schema() {
$schema['zariz_snapshot'] = array(
'description' => 'An instance of a Snapshot.',
'fields' => array(
'sid' => array(
'description' => 'Primary Key: Unique ID.',
'type' => 'serial',
'unsigned' => TRUE,
),
'nid' => array(
'description' => "The branch node ID.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'parent_sid' => array(
'description' => "The snapshot ID of the previous snapshot.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'locked' => array(
'description' => 'Boolean indicating whether the Snapshot is locked and cannot be edited.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'Timestamp for when the snapshot was created.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
),
'primary key' => array('sid'),
'indexes' => array(
'nid' => array('nid'),
),
'foreign keys' => array(
'node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
),
);
return $schema;
}
/**
* Implements hook_install().
*
* Add Zariz related fields.
*/
function zariz_install() {
og_create_field(OG_GROUP_FIELD, 'node', 'branch');
$info = array(
// Branch reference to the Branch content type.
'field_parent_branch' => array(
'label' => 'Parent branch',
'target_type' => 'node',
'target_bundles' => array('branch'),
'default_value_function' => 'entityreference_prepopulate_field_default_value',
'instance_settings' => array(
// Add entity reference prepopulate.
'behaviors' => array(
'prepopulate' => array(
'action' => 'hide',
'fallback' => 'hide',
'action_on_edit' => TRUE,
'status' => TRUE,
'providers' => array(
'og_context' => TRUE,
),
),
),
),
),
// Last node reference to the Snapshot entity.
'field_last_node' => array(
'label' => 'Last node',
'target_type' => 'node',
'target_bundles' => array(),
'entity_type' => 'snapshot',
'bundle' => 'snapshot',
),
// Last term reference to the Snapshot entity.
'field_last_term' => array(
'label' => 'Last term',
'target_type' => 'taxonomy_term',
'target_bundles' => array(),
'entity_type' => 'snapshot',
'bundle' => 'snapshot',
),
);
foreach ($info as $field_name => $value) {
$value += array(
'entity_type' => 'node',
'bundle' => 'branch',
'cardinality' => 1,
'instance_settings' => array(),
'default_value_function' => '',
);
if (!field_info_field($field_name)) {
$field = array(
'entity_types' => array($value['entity_type']),
'settings' => array(
'handler' => 'base',
'target_type' => $value['target_type'],
'handler_settings' => array(
'target_bundles' => $value['target_bundles'],
),
),
'field_name' => $field_name,
'type' => 'entityreference',
'cardinality' => $value['cardinality'],
);
field_create_field($field);
}
if (!field_info_instance($value['entity_type'], $field_name, $value['bundle'])) {
$instance = array(
'entity_type' => $value['entity_type'],
'field_name' => $field_name,
'bundle' => $value['bundle'],
'label' => $value['label'],
'settings' => $value['instance_settings'],
);
if (!empty($value['default_value_function'])) {
$instance['default_value_function'] = $value['default_value_function'];
}
field_create_instance($instance);
}
}
// Merged field, to Indicate if a branch is merged.
$field_name = 'field_branch_merged';
if (!field_info_field($field_name)) {
$field = array(
'field_name' => $field_name,
'type' => 'list_boolean',
'cardinality' => 1,
);
field_create_field($field);
}
if (!field_info_instance('node', $field_name, 'branch')) {
$instance = array(
'entity_type' => 'node',
'field_name' => $field_name,
'bundle' => 'branch',
'label' => t('Is merged'),
'description' => t('Indicates if a branch is merged.'),
'widget' => array(
'module' => 'options',
'settings' => array(
'display_label' => TRUE,
),
'type' => 'options_onoff',
),
);
field_create_instance($instance);
}
}
/**
* Implements hook_uninstall().
*/
function zariz_uninstall() {
variable_del('zariz_master_branch');
}