-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolf.install
80 lines (58 loc) · 1.82 KB
/
golf.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
<?php
include('install/golf_scores.features.inc');
include('install/golf_scores.features.field_base.inc');
include('install/golf_scores.features.field_instance.inc');
// include('features/golf_content_types/golf_content_types.field_group.inc');
/**
* Implements hook_install().
*/
function golf_install() {
foreach (golf_scores_node_info() as $key => $value) {
$value['type'] = $key;
node_type_save($value);
}
add_custom_fields();
// Add field groups
// foreach (golf_content_types_field_group_info() as $key => $value) {
// field_group_group_save($value);
// }
cache_clear_all();
}
/**
* Implements hook_uninstall().
*/
function golf_uninstall() {
foreach (golf_scores_node_info() as $key => $value) {
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $key));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
delete_custom_fields();
node_type_delete($key);
field_purge_batch(500);
}
cache_clear_all();
}
function add_custom_fields() {
foreach (golf_scores_field_default_field_bases() as $field) {
field_create_field($field);
}
foreach (golf_scores_field_default_field_instances() as $fieldinstance) {
// $fieldinstance['entity_type'] = 'node';
// $fieldinstance['bundle'] = 'round';
// print_r($fieldinstance);
field_create_instance($fieldinstance);
}
}
function delete_custom_fields() {
foreach (array_keys(golf_scores_field_default_field_bases()) as $field) {
field_delete_field($field);
}
// $instances = field_info_instances('node', 'round');
// foreach ($instances as $instance_name => $fieldinstance) {
// field_delete_instance($fieldinstance);
// }
}