1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Fetch metadata on a specific page_wizard plugin.
|
9
|
*
|
10
|
* @param $page_wizard
|
11
|
* Name of a panel page_wizard.
|
12
|
*
|
13
|
* @return
|
14
|
* An array with information about the requested panel page_wizard.
|
15
|
*/
|
16
|
function page_manager_get_page_wizard($page_wizard) {
|
17
|
ctools_include('plugins');
|
18
|
return ctools_get_plugins('page_manager', 'page_wizards', $page_wizard);
|
19
|
}
|
20
|
|
21
|
/**
|
22
|
* Fetch metadata for all page_wizard plugins.
|
23
|
*
|
24
|
* @return
|
25
|
* An array of arrays with information about all available panel page_wizards.
|
26
|
*/
|
27
|
function page_manager_get_page_wizards() {
|
28
|
ctools_include('plugins');
|
29
|
return ctools_get_plugins('page_manager', 'page_wizards');
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* Get the cached changes to a given wizard.
|
34
|
*
|
35
|
* @return
|
36
|
* A $cache object or a clean cache object if none could be loaded.
|
37
|
*/
|
38
|
function page_manager_get_wizard_cache($plugin) {
|
39
|
if (is_string($plugin)) {
|
40
|
$plugin = page_manager_get_page_wizard($plugin);
|
41
|
}
|
42
|
|
43
|
if (empty($plugin)) {
|
44
|
return;
|
45
|
}
|
46
|
|
47
|
ctools_include('object-cache');
|
48
|
|
49
|
// Since contexts might be cache, include this so they load.
|
50
|
ctools_include('context');
|
51
|
$cache = ctools_object_cache_get('page_manager_page_wizard', $plugin['name']);
|
52
|
if (!$cache) {
|
53
|
$cache = page_manager_make_wizard_cache($plugin);
|
54
|
}
|
55
|
|
56
|
return $cache;
|
57
|
}
|
58
|
|
59
|
function page_manager_make_wizard_cache($plugin) {
|
60
|
$cache = new stdClass();
|
61
|
$cache->plugin = $plugin;
|
62
|
if ($function = ctools_plugin_get_function($plugin, 'default cache')) {
|
63
|
$function($cache);
|
64
|
}
|
65
|
|
66
|
return $cache;
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Store changes to a task handler in the object cache.
|
71
|
*/
|
72
|
function page_manager_set_wizard_cache($cache) {
|
73
|
ctools_include('object-cache');
|
74
|
ctools_object_cache_set('page_manager_page_wizard', $cache->plugin['name'], $cache);
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Remove an item from the object cache.
|
79
|
*/
|
80
|
function page_manager_clear_wizard_cache($name) {
|
81
|
ctools_include('object-cache');
|
82
|
ctools_object_cache_clear('page_manager_page_wizard', $name);
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Menu callback for the page wizard.
|
87
|
*/
|
88
|
function page_manager_page_wizard($name, $step = NULL) {
|
89
|
$plugin = page_manager_get_page_wizard($name);
|
90
|
if (!$plugin) {
|
91
|
return MENU_NOT_FOUND;
|
92
|
}
|
93
|
|
94
|
// Check for simple access string on plugin.
|
95
|
if (!empty($plugin['access']) && !user_access($plugin['access'])) {
|
96
|
return MENU_ACCESS_DENIED;
|
97
|
}
|
98
|
|
99
|
// Check for possibly more complex access callback on plugin.
|
100
|
if (($function = ctools_plugin_get_function($plugin, 'access callback')) && !$function($plugin)) {
|
101
|
return MENU_ACCESS_DENIED;
|
102
|
}
|
103
|
|
104
|
// Create a basic wizard.in form info array and merge it with the
|
105
|
// plugin's.
|
106
|
$form_info = array(
|
107
|
'id' => 'page_manager_page_wizard',
|
108
|
'show trail' => TRUE,
|
109
|
'show back' => TRUE,
|
110
|
'show return' => FALSE,
|
111
|
'show cancel' => FALSE,
|
112
|
'next callback' => 'page_manager_page_wizard_next',
|
113
|
'finish callback' => 'page_manager_page_wizard_finish',
|
114
|
|
115
|
'path' => "admin/structure/pages/wizard/$name/%step",
|
116
|
);
|
117
|
|
118
|
$form_info = array_merge_recursive($form_info, $plugin['form info']);
|
119
|
|
120
|
// If step is unset, go with the basic step.
|
121
|
if (!isset($step)) {
|
122
|
$step = current(array_keys($form_info['order']));
|
123
|
$cache = page_manager_make_wizard_cache($plugin);
|
124
|
}
|
125
|
else {
|
126
|
$cache = page_manager_get_wizard_cache($plugin);
|
127
|
}
|
128
|
|
129
|
ctools_include('wizard');
|
130
|
$form_state = array(
|
131
|
'plugin' => $plugin,
|
132
|
'wizard cache' => $cache,
|
133
|
'type' => 'edit',
|
134
|
'rerender' => TRUE,
|
135
|
'step' => $step,
|
136
|
);
|
137
|
|
138
|
if (isset($plugin['page title'])) {
|
139
|
drupal_set_title($plugin['page title']);
|
140
|
}
|
141
|
|
142
|
if ($function = ctools_plugin_get_function($form_state['plugin'], 'start')) {
|
143
|
$function($form_info, $step, $form_state);
|
144
|
}
|
145
|
|
146
|
$output = ctools_wizard_multistep_form($form_info, $step, $form_state);
|
147
|
return $output;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Callback generated when the add page process is finished.
|
152
|
*/
|
153
|
function page_manager_page_wizard_finish(&$form_state) {
|
154
|
if ($function = ctools_plugin_get_function($form_state['plugin'], 'finish')) {
|
155
|
$function($form_state);
|
156
|
}
|
157
|
|
158
|
page_manager_clear_wizard_cache($form_state['wizard cache']->plugin['name']);
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* Callback generated when the 'next' button is clicked.
|
163
|
*
|
164
|
* All we do here is store the cache.
|
165
|
*/
|
166
|
function page_manager_page_wizard_next(&$form_state) {
|
167
|
if ($function = ctools_plugin_get_function($form_state['plugin'], 'next')) {
|
168
|
$function($form_state);
|
169
|
}
|
170
|
|
171
|
page_manager_set_wizard_cache($form_state['wizard cache']);
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* Provide a simple administrative list of all wizards.
|
176
|
*
|
177
|
* This is called as a page callback, but can also be used by any module
|
178
|
* that wants to get a list of wizards for its type.
|
179
|
*/
|
180
|
function page_manager_page_wizard_list($type = NULL) {
|
181
|
$plugins = page_manager_get_page_wizards();
|
182
|
if (empty($plugins)) {
|
183
|
return '<p>' . t('There are no wizards available at this time.') . '</p>';
|
184
|
}
|
185
|
|
186
|
uasort($plugins, 'ctools_plugin_sort');
|
187
|
|
188
|
$output = '<dl class="page-manager-wizards">';
|
189
|
foreach ($plugins as $id => $plugin) {
|
190
|
if (!$type || (isset($plugin['type']) && $plugin['type'] == $type)) {
|
191
|
$output .= '<dt>' . l($plugin['title'], 'admin/structure/pages/wizard/' . $id) . '</dt>';
|
192
|
$output .= '<dd class="description">' . $plugin['description'] . '</dd>';
|
193
|
}
|
194
|
}
|
195
|
$output .= '</dl>';
|
196
|
|
197
|
return $output;
|
198
|
}
|