View source
<?php
function page_manager_get_page_wizard($page_wizard) {
ctools_include('plugins');
return ctools_get_plugins('page_manager', 'page_wizards', $page_wizard);
}
function page_manager_get_page_wizards() {
ctools_include('plugins');
return ctools_get_plugins('page_manager', 'page_wizards');
}
function page_manager_get_wizard_cache($plugin) {
if (is_string($plugin)) {
$plugin = page_manager_get_page_wizard($plugin);
}
if (empty($plugin)) {
return;
}
ctools_include('object-cache');
ctools_include('context');
$cache = ctools_object_cache_get('page_manager_page_wizard', $plugin['name']);
if (!$cache) {
$cache = page_manager_make_wizard_cache($plugin);
}
return $cache;
}
function page_manager_make_wizard_cache($plugin) {
$cache = new stdClass();
$cache->plugin = $plugin;
if ($function = ctools_plugin_get_function($plugin, 'default cache')) {
$function($cache);
}
return $cache;
}
function page_manager_set_wizard_cache($cache) {
ctools_include('object-cache');
ctools_object_cache_set('page_manager_page_wizard', $cache->plugin['name'], $cache);
}
function page_manager_clear_wizard_cache($name) {
ctools_include('object-cache');
ctools_object_cache_clear('page_manager_page_wizard', $name);
}
function page_manager_page_wizard($name, $step = NULL) {
$plugin = page_manager_get_page_wizard($name);
if (!$plugin) {
return MENU_NOT_FOUND;
}
if (!empty($plugin['access']) && !user_access($plugin['access'])) {
return MENU_ACCESS_DENIED;
}
if ($function = ctools_plugin_get_function($plugin, 'access callback') && !$function($plugin)) {
return MENU_ACCESS_DENIED;
}
$form_info = array(
'id' => 'page_manager_page_wizard',
'show trail' => TRUE,
'show back' => TRUE,
'show return' => FALSE,
'show cancel' => FALSE,
'next callback' => 'page_manager_page_wizard_next',
'finish callback' => 'page_manager_page_wizard_finish',
'path' => "admin/build/pages/wizard/{$name}/%step",
);
$form_info = array_merge_recursive($form_info, $plugin['form info']);
if (!isset($step)) {
$step = current(array_keys($form_info['order']));
$cache = page_manager_make_wizard_cache($plugin);
}
else {
$cache = page_manager_get_wizard_cache($plugin);
}
ctools_include('wizard');
$form_state = array(
'plugin' => $plugin,
'cache' => $cache,
'type' => 'edit',
'rerender' => TRUE,
'step' => $step,
);
if (isset($plugin['page title'])) {
drupal_set_title($plugin['page title']);
}
if ($function = ctools_plugin_get_function($form_state['plugin'], 'start')) {
$function($form_info, $step, $form_state);
}
$output = ctools_wizard_multistep_form($form_info, $step, $form_state);
return $output;
}
function page_manager_page_wizard_finish(&$form_state) {
if ($function = ctools_plugin_get_function($form_state['plugin'], 'finish')) {
$function($form_state);
}
page_manager_clear_wizard_cache($form_state['cache']->plugin['name']);
}
function page_manager_page_wizard_next(&$form_state) {
if ($function = ctools_plugin_get_function($form_state['plugin'], 'next')) {
$function($form_state);
}
page_manager_set_wizard_cache($form_state['cache']);
}
function page_manager_page_wizard_list($type = NULL) {
$plugins = page_manager_get_page_wizards();
uasort($plugins, 'ctools_plugin_sort');
$output = '<dl class="page-manager-wizards">';
foreach ($plugins as $id => $plugin) {
if (!$type || isset($plugin['type']) && $plugin['type'] == $type) {
$output .= '<dt>' . l($plugin['title'], 'admin/build/pages/wizard/' . $id) . '</dt>';
$output .= '<dd class="description">' . $plugin['description'] . '</dd>';
}
}
$output .= '</dl>';
return $output;
}