1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Features support for Variable store.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_features_export_options().
|
10
|
*/
|
11
|
function variable_realm_features_export_options() {
|
12
|
foreach (variable_realm_info() as $name => $realm) {
|
13
|
$controller = variable_realm_controller($name);
|
14
|
$realm_keys = $controller->getAllKeys();
|
15
|
if (count($realm_keys) > 1) {
|
16
|
$options[$name] = $controller->getTitle() . ': ' . t('all');
|
17
|
}
|
18
|
foreach ($realm_keys as $key => $title) {
|
19
|
$options[$name . ':' . $key] = $controller->getTitle() . ': ' . $title;
|
20
|
}
|
21
|
}
|
22
|
return $options;
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* Implements hook_features_export().
|
27
|
*/
|
28
|
function variable_realm_features_export($data, &$export, $module_name) {
|
29
|
$export['dependencies']['variable_realm'] = 'variable_realm';
|
30
|
$list = variable_realm_features_selection($data);
|
31
|
foreach ($list as $machine_name) {
|
32
|
// Add module that provides the exported realm
|
33
|
list($realm, $key) = explode(':', $machine_name, 2); // limit 2 because keys can contain colons
|
34
|
if ($realm_info = variable_realm_info($realm)) {
|
35
|
$export['dependencies'][$realm_info['module']] = $realm_info['module'];
|
36
|
}
|
37
|
$export['features']['variable_realm'][$machine_name] = $machine_name;
|
38
|
}
|
39
|
return array();
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Processes export data selections consistently.
|
44
|
*
|
45
|
* @param $data
|
46
|
* Array of selections from the features component form.
|
47
|
*
|
48
|
* @return
|
49
|
* An array of realms, keyed by machine_name.
|
50
|
*/
|
51
|
function variable_realm_features_selection($data) {
|
52
|
$list = array();
|
53
|
foreach ($data as $machine_name) {
|
54
|
if (strpos($machine_name, ':')) {
|
55
|
$list[] = $machine_name;
|
56
|
}
|
57
|
else {
|
58
|
foreach (variable_realm_keys($machine_name) as $key => $title) {
|
59
|
$list[] = "$machine_name:$key";
|
60
|
}
|
61
|
}
|
62
|
}
|
63
|
return $list;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Implements hook_features_export_render().
|
68
|
*/
|
69
|
function variable_realm_features_export_render($module_name, $data, $export = NULL) {
|
70
|
variable_realm_features_load($module_name, 'variable_realm_default_variables', FALSE);
|
71
|
$code = array();
|
72
|
$code[] = '$realm_variables = array();';
|
73
|
foreach ($data as $machine_name) {
|
74
|
list($realm, $key) = explode(':', $machine_name, 2); // limit 2 because keys can contain colons
|
75
|
$variable_realm = variable_realm($realm, $key);
|
76
|
$variables = $variable_realm->variable_list();
|
77
|
$code[] = " \$realm_variables['{$realm}']['{$key}'] = " . features_var_export($variables) .";";
|
78
|
}
|
79
|
$code[] = "\nreturn \$realm_variables;";
|
80
|
$output = implode("\n", $code);
|
81
|
return array('variable_realm_default_variables' => $output);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Implements hook_features_revert().
|
86
|
*/
|
87
|
function variable_realm_features_revert($module) {
|
88
|
return variable_realm_features_rebuild($module);
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Implements hook_features_rebuild().
|
93
|
*/
|
94
|
function variable_realm_features_rebuild($module) {
|
95
|
if ($defaults = variable_realm_features_load($module, 'variable_realm_default_variables', TRUE)) {
|
96
|
foreach ($defaults as $realm => $realm_data) {
|
97
|
foreach ($realm_data as $key => $variables) {
|
98
|
$variable_realm = variable_realm($realm, $key);
|
99
|
foreach ($variables as $name => $value) {
|
100
|
$variable_realm->variable_set($name, $value);
|
101
|
}
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* Features doesn't know how to load custom includes.
|
109
|
*
|
110
|
* @param $module
|
111
|
* The name of the feature to load.
|
112
|
* @param $hook
|
113
|
* The name of the domain hook.
|
114
|
* @param $return
|
115
|
* Boolean indicator to return the results of the function.
|
116
|
*
|
117
|
* @return
|
118
|
* The results of the $hook implemenation, if requested.
|
119
|
*/
|
120
|
function variable_realm_features_load($module, $hook, $return = TRUE) {
|
121
|
// Features does not handle module loading of custom files.
|
122
|
module_load_include('inc', $module, $module . '.variable');
|
123
|
$function = $module . '_' . $hook;
|
124
|
if ($return && function_exists($function)) {
|
125
|
return $function();
|
126
|
}
|
127
|
}
|