-
Notifications
You must be signed in to change notification settings - Fork 0
/
hierarchical_select.features.inc
99 lines (84 loc) · 3.01 KB
/
hierarchical_select.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
93
94
95
96
97
98
99
<?php
/**
* @file
* Integration with the features module.
*/
/**
* Implements hook_features_export().
*/
function hierarchical_select_features_export($data, &$export, $module_name) {
// Add hierarchical_select dependency.
$export['dependencies']['hierarchical_select'] = 'hierarchical_select';
// Retrieve dependencies from all information items.
$dependencies = array();
foreach (module_implements('hierarchical_select_config_info') as $module) {
$configs = module_invoke($module, 'hierarchical_select_config_info');
foreach ($configs as $config_id => $config) {
$dependencies[$config_id] = $module;
}
}
// Add features and dependencies.
foreach ($data as $config_id) {
$export['features']['hierarchical_select'][$config_id] = $config_id;
if (isset($dependencies[$config_id])) {
$module = $dependencies[$config_id];
$export['dependencies'][$module] = $module;
}
}
return array();
}
/**
* Implements hook_features_export_options().
*/
function hierarchical_select_features_export_options() {
// Retrieve all information items.
$info_items = array();
foreach (module_implements('hierarchical_select_config_info') as $module) {
$info_items = array_merge_recursive($info_items, module_invoke($module, 'hierarchical_select_config_info'));
}
// Process the retrieved information into options.
$options = array();
foreach ($info_items as $id => $item) {
$config_id = $item['config_id'];
$options[$config_id] = $item['hierarchy type'] . ': ' . $item['hierarchy'] . ' - ' . $item['context type'] . (!empty($item['context']) ? ': ' . $item['context'] : '');
}
return $options;
}
/**
* Implements hook_features_export_render().
*/
function hierarchical_select_features_export_render($module, $data) {
module_load_include('inc', 'hierarchical_select', 'includes/common');
module_load_include('inc', 'hierarchical_select', 'hierarchical_select.admin');
$code = array();
$code[] = '$configs = array();';
foreach ($data as $config_id) {
$config = hierarchical_select_common_config_get($config_id);
$config['config_id'] = $config_id;
$code[] = _hierarchical_select_create_export_code($config);
$code[] = "\$configs['{$config_id}'] = \$config;";
}
$code[] = "return \$configs;";
$code = implode("\n", $code);
return array('hierarchical_select_default_configs' => $code);
}
/**
* Implements hook_features_revert().
*/
function hierarchical_select_features_revert($module) {
hierarchical_select_features_rebuild($module);
}
/**
* Implements hook_features_rebuild().
*/
function hierarchical_select_features_rebuild($module) {
module_load_include('inc', 'hierarchical_select', 'includes/common');
$configs = features_get_default('hierarchical_select', $module);
if (!empty($configs)) {
// Apply the configuration.
require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
foreach ($configs as $config_id => $config) {
hierarchical_select_common_config_set($config_id, $config);
}
}
}