-
Notifications
You must be signed in to change notification settings - Fork 2
/
metatag.features.inc
98 lines (87 loc) · 2.47 KB
/
metatag.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
<?php
/**
* @file
* Features integration for the Metatag module.
*/
/**
* Implements hook_features_export().
*/
function metatag_features_export($data, &$export, $module_name = '', $type = 'metatag') {
$pipe = array();
foreach ($data as $name) {
if (metatag_config_load($name)) {
$export['features'][$type][$name] = $name;
}
}
$export['dependencies']['metatag'] = 'metatag';
return $pipe;
}
/**
* Implements hook_features_export_render().
*/
function metatag_features_export_render($module_name, $data, $export = NULL) {
$code = array();
$code[] = ' $config = array();';
$code[] = '';
foreach ($data as $key => $name) {
if (is_object($name)) {
$name = $name->instance;
}
if ($config = metatag_config_load($name)) {
$export = new stdClass();
$export->instance = $config->instance;
if (isset($config->disabled)) {
$export->disabled = $config->disabled;
}
$export->config = $config->config;
$export = features_var_export($export, ' ');
$key = features_var_export($name);
$code[] = " // Exported Metatag config instance: {$name}.";
$code[] = " \$config[{$key}] = {$export};";
$code[] = "";
}
}
$code[] = ' return $config;';
$code = implode("\n", $code);
return array('metatag_export_default' => $code);
}
/**
* Implements hook_features_revert().
*/
function metatag_features_revert($module) {
if ($feature_conf = features_get_default('metatag', $module)) {
foreach (array_keys($feature_conf) as $config) {
if ($conf = metatag_config_load($config)) {
db_delete('metatag_config')->condition('instance', $config)->execute();
}
unset($feature_conf[$config]['cid']);
$object = new stdClass();
$object->cid = NULL;
$object->instance = $config;
$object->config = $feature_conf[$config]['config'];
metatag_config_save($object);
if (!empty($feature_conf[$config]['disabled'])) {
ctools_export_crud_disable('metatag_config', $config);
}
else {
ctools_export_crud_enable('metatag_config', $config);
}
}
}
}
/**
* Implements hook_features_export_options().
*/
function metatag_features_export_options() {
$instances = metatag_config_instance_info();
foreach ($instances as $key => $instance) {
$options[$key] = $key;
};
return $options;
}
/**
* Implements hook_features_rebuild().
*/
function metatag_features_rebuild($module) {
metatag_features_revert($module);
}