-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultigraph.install
More file actions
executable file
·369 lines (328 loc) · 11.8 KB
/
multigraph.install
File metadata and controls
executable file
·369 lines (328 loc) · 11.8 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
require_once DRUPAL_ROOT.'/'.drupal_get_path('module','multigraph')."/multigraph_functions.inc";
/**
* Implements hook_install().
*/
function multigraph_install() {
node_types_rebuild();
foreach (_multigraph_field_specs() as $field_spec) {
field_create_field($field_spec['field_config']);
$instance = $field_spec['field_instance'];
$instance['entity_type'] = 'node';
$instance['bundle'] = 'multigraph';
field_create_instance($instance);
}
}
/*
* Return an array of "Field Spec" arrays, one for each field to be defined for the Multigraph
* content type. Each Field Spec array has exactly two keys:
* 'field_config': a field definition array, as expected by field_create_field()
* 'field_instance': a field instance definition array, as expected by field_create_instance()
* Note: the Field Spec array concept is just a convenience used within this module's code; it is
* not part of Drupal's Field API The field definition array, and field instance definition array,
* however, are part of the Field API.
*/
function _multigraph_field_specs() {
$field_specs = array();
$field_specs[] = _multigraph_textarea_field_spec(array(
'field_name' => 'field_multigraph_description',
'label' => 'Description',
'description' => 'Enter an optional description for this graph here.',
'required' => 0,
'widget_rows' => 2,
'widget_weight' => 10,
'default_display_label' => 'hidden',
'default_display_type' => 'text_default',
'default_display_weight' => 10,
'teaser_display_label' => 'hidden',
'teaser_display_type' => 'text_default',
'teaser_display_weight' => 10,
));
$field_specs[] = _multigraph_dimension_field(array(
'field_name' => 'field_multigraph_width',
'label' => 'Default Width',
'description' => 'The default width, in pixels, for this graph. This width'
. ' may be overridden any place where this graph is embedded.',
'default_value' => 500,
'min_value' => 1,
'max_value' => 2000,
'widget_weight' => 20,
'default_display_weight' => 20,
));
$field_specs[] = _multigraph_dimension_field(array(
'field_name' => 'field_multigraph_height',
'label' => 'Default Height',
'description' => 'The default height, in pixels, for this graph. This height'
. ' may be overridden any place where this graph is embedded.',
'default_value' => 400,
'min_value' => 1,
'max_value' => 2000,
'widget_weight' => 30,
'default_display_weight' => 30,
));
$field_specs[] = _multigraph_textarea_field_spec(array(
'field_name' => 'field_multigraph_mugl',
'label' => 'MUGL',
'description' => 'Enter the MUGL for this graph here.',
'required' => 1,
'widget_rows' => 10,
'widget_weight' => 40,
'default_display_label' => 'hidden',
'default_display_type' => 'hidden',
'default_display_weight' => 40,
'teaser_display_label' => 'hidden',
'teaser_display_type' => 'hidden',
'teaser_display_weight' => 40,
));
$field_specs[] = array(
'field_config' => array(
'active' => '1',
'cardinality' => '1',
'deleted' => '0',
'entity_types' => array(),
'field_name' => 'field_multigraph_swf',
'module' => 'list',
'settings' => array(
'allowed_values_function' => '_multigraph_available_swf_path_allowed_values',
),
'translatable' => '0',
'type' => 'list_text',
),
'field_instance' => array(
'bundle' => 'multigraph',
'default_value' => NULL,
'deleted' => '0',
'description' => '',
'display' => array(
'default' => array(
'label' => 'hidden',
'module' => 'list',
'settings' => array(),
'type' => 'hidden',
'weight' => 1,
),
'teaser' => array(
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
'entity_type' => 'node',
'field_name' => 'field_multigraph_swf',
'label' => 'SWF',
'description' => 'Choose the SWF for this Multigraph',
'required' => 1,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'weight' => '60',
),
),
);
return $field_specs;
}
/*
* Return a Field Spec array for an integer dimension field; this is used to define
* the Multigraph's "width" and "height" fields. This function takes a single array
* argument having the following keys:
*
* 'field_name' => 'field_multigraph_description'
* 'label' => 'Description'
* 'description' => 'Enter an optional description for this graph here.',
* 'required' => 0
* 'widget_rows' => '2'
* 'widget_weight' => '-4'
* 'default_display_label => 'above'
* 'default_display_weight => '0'
* 'teaser_display_label => 'above'
* 'teaser_display_weight => '0'
*/
function _multigraph_textarea_field_spec($field_spec_values) {
return array(
'field_config' => array(
'field_name' => $field_spec_values['field_name'],
'type' => 'text_long',
'cardinality' => '1',
'active' => '1',
'module' => 'text',
),
'field_instance' => array(
'field_name' => $field_spec_values['field_name'],
'label' => $field_spec_values['label'],
'description' => $field_spec_values['description'],
'required' => $field_spec_values['required'],
'widget' => array(
'active' => 1,
'module' => 'text',
'settings' => array(
'rows' => $field_spec_values['widget_rows'],
),
'type' => 'text_textarea',
'weight' => $field_spec_values['widget_weight'],
),
'display' => array(
'default' => array(
'label' => $field_spec_values['default_display_label'],
'module' => 'text',
'settings' => array(),
'type' => $field_spec_values['default_display_type'],
'weight' => $field_spec_values['default_display_weight'],
),
'teaser' => array(
'label' => $field_spec_values['teaser_display_label'],
'settings' => array(),
'type' => $field_spec_values['teaser_display_type'],
'weight' => $field_spec_values['teaser_display_weight'],
),
),
'settings' => array(
'text_processing' => '0',
'user_register_form' => FALSE,
),
),
);
}
function _multigraph_text_field_spec($field_spec_values) {
return array(
'field_config' => array(
'field_name' => $field_spec_values['field_name'],
'type' => 'text',
'cardinality' => '1',
'active' => '1',
'module' => 'text',
),
'field_instance' => array(
'field_name' => $field_spec_values['field_name'],
'label' => $field_spec_values['label'],
'description' => $field_spec_values['description'],
'required' => $field_spec_values['required'],
'widget' => array(
'active' => 1,
'module' => 'text',
'type' => 'text',
'weight' => $field_spec_values['widget_weight'],
),
'display' => array(
'default' => array(
'label' => $field_spec_values['default_display_label'],
'module' => 'text',
'type' => $field_spec_values['default_display_type'],
'weight' => $field_spec_values['default_display_weight'],
),
'teaser' => array(
'label' => $field_spec_values['teaser_display_label'],
'type' => $field_spec_values['teaser_display_type'],
'weight' => $field_spec_values['teaser_display_weight'],
),
),
'settings' => array(
'text_processing' => '0',
'user_register_form' => FALSE,
),
),
);
}
/*
* Return a Field Spec array for an integer dimension field; this is used to define
* the Multigraph's "width" and "height" fields. This function takes a single array
* argument having the following keys:
*
* 'field_name' => 'field_multigraph_width'
* 'label' => 'Default Width'
* 'description' => 'The default width, in pixels, for this graph. This width may be overridden any place where this graph is embedded.'
* 'default_value' => '400'
* 'min_value' => '1'
* 'max_value' => '2000'
* 'widget_weight' => '-2'
* 'default_display_weight' => '2'
*/
function _multigraph_dimension_field($field_spec_values) {
return array(
'field_config' => array(
'field_name' => $field_spec_values['field_name'],
'type' => 'number_integer',
'cardinality' => '1',
'active' => '1',
'module' => 'number',
),
'field_instance' => array(
'field_name' => $field_spec_values['field_name'],
'label' => $field_spec_values['label'],
'required' => 1,
'description' => $field_spec_values['description'],
'default_value' => array(0 => array('value' => $field_spec_values['default_value'])),
'settings' => array(
'max' => $field_spec_values['max_value'],
'min' => $field_spec_values['min_value'],
'prefix' => '',
'suffix' => '',
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 0,
'module' => 'number',
'settings' => array(),
'type' => 'number',
'weight' => $field_spec_values['widget_weight'],
),
'deleted' => '0',
'display' => array(
'default' => array(
'label' => 'hidden',
'module' => 'number',
'settings' => array(
'decimal_separator' => '.',
'prefix_suffix' => TRUE,
'scale' => 0,
'thousand_separator' => ' ',
),
'type' => 'hidden',
'weight' => $field_spec_values['default_display_weight'],
),
'teaser' => array(
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
),
);
}
/**
* Implements hook_uninstall().
*/
function multigraph_uninstall() {
// Gather all the example content that might have been created while this
// module was enabled.
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => 'multigraph'));
$nids = array();
foreach ($result as $row) {
$nids[] = $row->nid;
}
// Delete all the nodes at once
node_delete_multiple($nids);
// Loop over each of the fields defined by this module and delete
// all instances of the field, their data, and the field itself.
//foreach (array_keys(_multigraph_installed_fields()) as $field) {
foreach (_multigraph_field_specs() as $field) {
field_delete_field($field['field_config']['field_name']);
}
// Loop over any remaining field instances attached to the multigraph
// content type (such as the body field) and delete them individually.
$instances = field_info_instances('node', 'multigraph');
foreach ($instances as $instance_name => $instance) {
field_delete_instance($instance);
}
// Delete our content type
node_type_delete('multigraph');
// Purge all field infromation
field_purge_batch(1000);
}