-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuottawa_lang_editor.features.inc
92 lines (85 loc) · 2.82 KB
/
uottawa_lang_editor.features.inc
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
<?php
/**
* @file
* Functions related to the Features implementation.
*/
/**
* Implements hook_features_export_options().
*/
function uottawa_lang_editor_bundle_config_features_export_options() {
$options = array();
$rs = db_query('SELECT * FROM {uottawa_lang_editor_bundle_settings}');
foreach ($rs as $row) {
$options[$row->bundle_type] = $row->bundle_type;
}
return $options;
}
/**
* Implements hook_features_export().
*/
function uottawa_lang_editor_bundle_config_features_export($data, &$export, $module_name) {
$export['dependencies']['uottawa_lang_editor'] = 'uottawa_lang_editor';
foreach ($data as $bundle) {
$export['features']['uottawa_lang_editor_bundle_config'][$bundle] = $bundle;
}
}
/**
* Implements hook_features_export_render().
*/
function uottawa_lang_editor_bundle_config_features_export_render($module_name, $data, $export = NULL) {
$rs = db_query('SELECT * FROM {uottawa_lang_editor_bundle_settings}');
$bundle_info = array();
foreach ($rs as $row) {
$bundle_info[$row->bundle_type] = (array) $row;
unset($bundle_info[$row->bundle_type]['pkid']);
}
$rs = db_query('SELECT * FROM {uottawa_lang_editor_field_settings}');
$field_info = array();
foreach ($rs as $row) {
if (!isset($field_info[$row->bundle_type])) {
$field_info[$row->bundle_type] = array();
}
$field_info[$row->bundle_type][$row->field_name] = (array) $row;
unset($field_info[$row->bundle_type][$row->field_name]['pkid']);
}
$code = array();
$code[] = ' $bundles = array();';
$code[] = '';
foreach ($data as $bundle) {
$package = array(
'bundle' => $bundle_info[$bundle],
'fields' => $field_info[$bundle]
);
$code[] = ' $bundles[] = ' . features_var_export($package, ' ') . ';';
}
$code[] = ' return $bundles;';
return array('config_features_bundle_default_settings' => implode('\n', $code));
}
/**
* Implements hook_features_rebuild();
*/
function uottawa_lang_editor_bundle_config_features_rebuild($module) {
$items = module_invoke($module, 'config_features_bundle_default_settings');
foreach ($items as $item) {
$bundle = $item['bundle'];
db_merge('uottawa_lang_editor_bundle_settings')
->fields($bundle)
->key(array('bundle_type' => $bundle['bundle_type']))
->execute();
foreach ($item['fields'] as $field) {
db_merge('uottawa_lang_editor_field_settings')
->fields($field)
->key(array(
'bundle_type' => $field['bundle_type'],
'field_name' => $field['field_name']
))
->execute();
}
}
}
/**
* Implements hook_features_revert().
*/
function uottawa_lang_editor_config_features_revert($module) {
uottawa_lang_editor_bundle_config_features_rebuild($module);
}