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