forked from mrf/nodequeue_export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodequeue_export.features.inc
168 lines (153 loc) · 5.12 KB
/
nodequeue_export.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* Implementation of hook_features_export_options().
*
* This hook tells features what items of this component are available for export.
*
* @return array
* A keyed array of items, suitable for use with a FormAPI select or
* checkboxes element.
*/
function nodequeue_export_features_export_options() {
$options = array();
// Bypass cache to get all the queues straight from the db.
$queues = nodequeue_load_queues(nodequeue_get_all_qids(0), TRUE);
foreach ($queues as $qid => $data) {
$options[$data->name] = $data->title;
}
return $options;
}
/**
* Implementation of hook_features_export().
*
* When one of these components is selected on the features page, this hook
* includes the item (plus any dependencies) in the export array.
*
* @param array $data
* The machine name for this component.
* @param array &$export
* An array of components to be exported.
* @param string $module_name
* The name of the feature module that will be created.
* @return array
* An array of functions for further processing (if desired).
*/
function nodequeue_export_features_export($data, &$export, $module_name) {
// These are the dependencies for this module to function properly
$export['dependencies']['nodequeue_export'] = 'nodequeue';
$export['dependencies']['nodequeue_export'] = 'nodequeue_export';
// This is a simple straight object export.
foreach ($data as $component) {
$export['features']['nodequeue_export'][$component] = $component;
}
return array();
}
/**
* Implementation of hook_features_export_render().
*
* This hook is called to export the component(s) selected via the features UI.
*
* @param string $module_name
* The name of the feature module to be exported.
* @param array $data
* An array of machine name identifiers for the rendered objects.
* @param array $export
* An array with the full export for the feature (only called during update or recreate).
* @return array
* The PHP code (an array) that will be rendered.
*/
function nodequeue_export_features_export_render($module_name, $data, $export = NULL) {
$code = array();
$code[] = ' $nodequeue_export = array();';
$code[] = '';
foreach ($data as $machine_name) {
// Retrieve the nodequeue.
$queue = nodequeue_load_queue_by_name($machine_name);
// Format it in prep for export.
$queue_data = _nodequeue_export_format_queue_data($queue);
// Add the nodequeue to the feature.
if (isset($queue_data)) {
$code[] = ' $nodequeue_export[\'' .$queue_data['name'] .'\'] = ' .features_var_export($queue_data, ' ' ) .';';
}
}
$code[] = ' return $nodequeue_export;';
$code = implode("\n", $code);
return array('nodequeue_export_features_default_settings' => $code);
}
/**
* Implementation of hook_features_rebuild(). [component_hook]
*
* This is called whenever a new feature is enabled, or reverted.
*/
function nodequeue_export_features_rebuild($module) {
// Look for exported nodequeues.
$queues = module_invoke($module, 'nodequeue_export_features_default_settings');
// Loop over the queues to find the ones we need to recreate.
foreach ($queues as $id => $data) {
// Check to see if the queue already exists.
$exists = nodequeue_load_queue_by_name($data['name']);;
// If it doesn't, store the queue info in the database.
if (empty($exists)) {
$saved = _nodequeue_export_store_queue_data($data);
}
}
}
/**
* Implementation of hook_features_revert(). [component_hook]
*/
function nodequeue_export_features_revert($module) {
nodequeue_export_features_rebuild($module);
}
/**
* Take a nodequeue, loaded with the API, and format the data structure for export.
*/
function _nodequeue_export_format_queue_data($queue) {
$queue_data = array(
'name' => $queue->name,
'title' => $queue->title,
'size' => $queue->size,
'reverse' => $queue->reverse,
'link' => $queue->link,
'link_remove' => $queue->link_remove,
'owner' => $queue->owner,
'roles' => $queue->roles,
'types' => $queue->types,
'i18n' => $queue->i18n,
'show_in_links' => $queue->show_in_links,
'show_in_tab' => $queue->show_in_tab,
'show_in_ui' => $queue->show_in_ui,
'subqueues' => $queue->subqueues,
'add_subqueue' => array($queue->title),
'new' => TRUE,
);
return $queue_data;
}
/**
* Handle the actual creation of queue storage in the database.
*/
function _nodequeue_export_store_queue_data($data) {
$data = (object) $data;
dpm($data);
if (isset($data->name) && $dataname !== '') {
$queue = array(
'name' => $data->name,
'title' => $data->title,
'size' => $data->size,
'reverse' => $data->reverse,
'link' => $data->link,
'link_remove' => $data->link_remove,
'owner' => $data->owner,
'roles' => $data->roles,
'types' => $data->types,
'i18n' => $data->i18n,
'show_in_links' => $data->show_in_links,
'show_in_tab' => $data->show_in_tab,
'show_in_ui' => $data->show_in_ui,
'subqueues' => $data->subqueues,
'add_subqueue' => array($data->title),
'new' => TRUE,
);
$queue = (object) $queue;
nodequeue_save($queue);
}
}