-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfe_nodequeue.module
More file actions
138 lines (117 loc) · 3.59 KB
/
fe_nodequeue.module
File metadata and controls
138 lines (117 loc) · 3.59 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Implementation of hook_features_api().
*/
function fe_nodequeue_features_api() {
return array(
'fe_nodequeue' => array(
'name' => t('Nodequeues'),
'feature_source' => TRUE,
'default_hook' => 'fe_nodequeue_export_fields',
'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON,
)
);
}
/**
* Implementation of hook_features_export_options().
*/
function fe_nodequeue_features_export_options() {
$options = array();
$table = 'nodequeue_queue';
$query = "SELECT * FROM {{$table}}";
$fields = db_query($query);
while ($obj = $fields->fetchObject()) {
$options[$obj->name] = t('@name [@machine_name]', array('@name' => $obj->title, '@machine_name' => $obj->name));
}
return $options;
}
/**
* Implementation of hook_features_export().
*/
function fe_nodequeue_features_export($data, &$export, $module_name = '') {
$pipe = array();
$map = features_get_default_map('fe_nodequeue');
foreach ($data as $name) {
$export['dependencies']['fe_nodequeue'] = 'fe_nodequeue';
// If another module provides this style, add it as a dependency
if (isset($map[$name]) && $map[$name] != $module_name) {
$module = $map[$name];
$export['dependencies'][$module] = $module;
}
// Otherwise, export the nodequeue
elseif (nodequeue_load_queue_by_name($name)) {
$export['features']['fe_nodequeue'][$name] = $name;
}
}
return $pipe;
}
/**
* Implementation of hook_features_export_render().
*/
function fe_nodequeue_features_export_render($module_name = '', $data) {
$code = array();
$code[] = ' $nodequeues = array();';
$code[] = '';
foreach ($data as $name) {
if ($nodequeue = nodequeue_load_queue_by_name($name)) {
// sort roles and types arrays into ascending order so that we can
// check for overridden db data without being affected by the
// order in which this array gets stored/loaded.
if (!empty($nodequeue->roles)) {
sort($nodequeue->roles);
}
if (!empty($nodequeue->types)) {
sort($nodequeue->types);
}
$nodequeue_export = features_var_export($nodequeue, ' ');
$code[] = " // Exported nodequeues: {$nodequeue->name}";
$code[] = " \$nodequeues['{$name}'] = {$nodequeue_export};";
$code[] = "";
}
}
$code[] = ' return $nodequeues;';
$code = implode("\n", $code);
return array('fe_nodequeue_export_fields' => $code);
}
/**
* Implementation of hook_features_revert().
*/
function fe_nodequeue_features_revert($module) {
$defaults = features_get_default('fe_nodequeue', $module);
// Revert.
foreach ($defaults as $object) {
if (empty($object['name'])) {
continue;
}
if (!($nodequeue_queue = nodequeue_load_queue_by_name($object['name']))) {
unset($object['qid']);
$result = _fe_nodequeue_save_queue((array) $object);
} else {
$result = _fe_nodequeue_save_queue((array) $object);
}
}
return TRUE;
}
/**
* Implements hook_features_revert().
*/
function fe_nodequeue_features_rebuild($module) {
fe_nodequeue_features_revert($module);
}
/**
* Save a nodequeue queue.
*
* @param $settings
* @return array
*/
function _fe_nodequeue_save_queue($settings = array()) {
// Simulate checkboxes.
$settings['roles'] = drupal_map_assoc($settings['roles']);
$settings['types'] = drupal_map_assoc($settings['types']);
// Simulate submitting.
$form_state = array();
$form_state['values'] = $settings;
module_load_include('inc', 'nodequeue', 'includes/nodequeue.admin');
nodequeue_edit_queue_form_submit(NULL, $form_state);
return $settings;
}