4 * Fetch metadata on a specific page_wizard plugin.
7 * Name of a panel page_wizard.
10 * An array with information about the requested panel page_wizard.
12 function page_manager_get_page_wizard($page_wizard) {
13 ctools_include('plugins');
14 return ctools_get_plugins('page_manager', 'page_wizards', $page_wizard);
18 * Fetch metadata for all page_wizard plugins.
21 * An array of arrays with information about all available panel page_wizards.
23 function page_manager_get_page_wizards() {
24 ctools_include('plugins');
25 return ctools_get_plugins('page_manager', 'page_wizards');
29 * Get the cached changes to a given wizard.
32 * A $cache object or a clean cache object if none could be loaded.
34 function page_manager_get_wizard_cache($plugin) {
35 if (is_string($plugin)) {
36 $plugin = page_manager_get_page_wizard($plugin);
43 ctools_include('object-cache');
45 // Since contexts might be cache, include this so they load.
46 ctools_include('context');
47 $cache = ctools_object_cache_get('page_manager_page_wizard', $plugin['name']);
49 $cache = page_manager_make_wizard_cache($plugin);
55 function page_manager_make_wizard_cache($plugin) {
56 $cache = new stdClass;
57 $cache->plugin = $plugin;
58 if ($function = ctools_plugin_get_function($plugin, 'default cache')) {
66 * Store changes to a task handler in the object cache.
68 function page_manager_set_wizard_cache($cache) {
69 ctools_include('object-cache');
70 ctools_object_cache_set('page_manager_page_wizard', $cache->plugin['name'], $cache);
74 * Remove an item from the object cache.
76 function page_manager_clear_wizard_cache($name) {
77 ctools_include('object-cache');
78 ctools_object_cache_clear('page_manager_page_wizard', $name);
82 * Menu callback for the page wizard.
84 function page_manager_page_wizard($name, $step = NULL) {
85 $plugin = page_manager_get_page_wizard($name);
87 return MENU_NOT_FOUND;
90 // Check for simple access string on plugin.
91 if (!empty($plugin['access']) && !user_access($plugin['access'])) {
92 return MENU_ACCESS_DENIED;
95 // Check for possibly more complex access callback on plugin.
96 if ($function = ctools_plugin_get_function($plugin, 'access callback') && !$function($plugin)) {
97 return MENU_ACCESS_DENIED;
100 // Create a basic wizard.in form info array and merge it with the
103 'id' => 'page_manager_page_wizard',
104 'show trail' => TRUE,
106 'show return' => FALSE,
107 'show cancel' => FALSE,
108 'next callback' => 'page_manager_page_wizard_next',
109 'finish callback' => 'page_manager_page_wizard_finish',
111 'path' => "admin/structure/pages/wizard/$name/%step",
114 $form_info = array_merge_recursive($form_info, $plugin['form info']);
116 // If step is unset, go with the basic step.
118 $step = current(array_keys($form_info['order']));
119 $cache = page_manager_make_wizard_cache($plugin);
122 $cache = page_manager_get_wizard_cache($plugin);
125 ctools_include('wizard');
128 'wizard cache' => $cache,
134 if (isset($plugin['page title'])) {
135 drupal_set_title($plugin['page title']);
138 if ($function = ctools_plugin_get_function($form_state['plugin'], 'start')) {
139 $function($form_info, $step, $form_state);
142 $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
147 * Callback generated when the add page process is finished.
149 function page_manager_page_wizard_finish(&$form_state) {
150 if ($function = ctools_plugin_get_function($form_state['plugin'], 'finish')) {
151 $function($form_state);
154 page_manager_clear_wizard_cache($form_state['wizard cache']->plugin['name']);
158 * Callback generated when the 'next' button is clicked.
160 * All we do here is store the cache.
162 function page_manager_page_wizard_next(&$form_state) {
163 if ($function = ctools_plugin_get_function($form_state['plugin'], 'next')) {
164 $function($form_state);
167 page_manager_set_wizard_cache($form_state['wizard cache']);
171 * Provide a simple administrative list of all wizards.
173 * This is called as a page callback, but can also be used by any module
174 * that wants to get a list of wizards for its type.
176 function page_manager_page_wizard_list($type = NULL) {
177 $plugins = page_manager_get_page_wizards();
178 if (empty($plugins)) {
179 return '<p>' . t('There are no wizards available at this time.') . '</p>';
182 uasort($plugins, 'ctools_plugin_sort');
184 $output = '<dl class="page-manager-wizards">';
185 foreach ($plugins as $id => $plugin) {
186 if (!$type || (isset($plugin['type']) && $plugin['type'] == $type)) {
187 $output .= '<dt>' . l($plugin['title'], 'admin/structure/pages/wizard/' . $id) . '</dt>';
188 $output .= '<dd class="description">' . $plugin['description'] . '</dd>';