diff --git a/delegator/delegator.install b/delegator/delegator.install index 6150fba3fdb70278b4850cd9b196e8d35bcf8b34..a27afeb8fd57809b0a9f0ca463d10f82f1831184 100644 --- a/delegator/delegator.install +++ b/delegator/delegator.install @@ -110,7 +110,7 @@ function delegator_schema_1() { 'length' => '255', 'description' => 'Unique ID for this subtask. Used to identify it programmatically.', ), - 'type' => array( + 'task' => array( 'type' => 'varchar', 'length' => '255', 'description' => 'What type of page this is, so that we can use the same mechanism for creating tighter UIs for targeted pages.', @@ -207,3 +207,21 @@ function delegator_update_6100() { return $ret; } + +/** + * Change 'type' field to 'task'. + */ +function delegator_update_6101() { + $ret = array(); + $task = array( + 'type' => 'varchar', + 'length' => '255', + 'description' => 'What type of page this is, so that we can use the same mechanism for creating tighter UIs for targeted pages.', + 'initial' => 'page', + ); + + db_drop_field($ret, 'delegator_pages', 'type'); + db_add_field($ret, 'delegator_pages', 'task', $task); + + return $ret; +} diff --git a/delegator/delegator.module b/delegator/delegator.module index 5f26d5d91a3106b1af6fdf1f798794580a3ffa35..d828e039dfeeb28d9630170e45d6ea7af8f63a3c 100644 --- a/delegator/delegator.module +++ b/delegator/delegator.module @@ -777,3 +777,44 @@ function delegator_task_handler_ctools_access_set($argument, $access) { } } +/** + * Load a context from an argument for a given page task. + * + * This is used as a menu callback to translate arguments and that is why it is + * here in the .module file. + * + * @param $value + * The incoming argument value. + * @param $subtask + * The subtask id. + * @param $argument + * The numeric position of the argument in the path, counting from 0. + * + * @return + * A context item if one is configured, the argument if one is not, or + * FALSE if restricted or invalid. + */ +function _dp_arg_load($value, $subtask, $argument) { + $page = delegator_page_load($subtask); + if (!$page) { + return FALSE; + } + + $path = explode('/', $page->path); + if (empty($path[$argument])) { + return FALSE; + } + + $keyword = substr($path[$argument], 1); + if (empty($page->arguments[$keyword])) { + return $value; + } + + $page->arguments[$keyword]['keyword'] = $keyword; + + ctools_include('context'); + $context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value); + + // convert false equivalents to false. + return $context ? $context : FALSE; +} diff --git a/delegator/plugins/tasks/page.admin.inc b/delegator/plugins/tasks/page.admin.inc index f8591bec6a295de94d673cb304e2a5fc707ab87d..3bd08581716e378c41857b67c3c172928db40e4b 100644 --- a/delegator/plugins/tasks/page.admin.inc +++ b/delegator/plugins/tasks/page.admin.inc @@ -28,13 +28,14 @@ function delegator_page_menu(&$items, $task) { 'title' => 'Add page', 'description' => 'Add a delegator page subtask.', 'page callback' => 'delegator_page_add_subtask', + 'page arguments' => array('page'), 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/build/pages/import'] = array( 'title' => 'Import page', 'description' => 'Import a delegator page subtask.', 'page callback' => 'drupal_get_form', - 'page arguments' => array('delegator_page_import_subtask'), + 'page arguments' => array('delegator_page_import_subtask', 'page'), 'type' => MENU_LOCAL_TASK, ) + $base; @@ -48,9 +49,9 @@ function delegator_page_menu(&$items, $task) { $default_task = TRUE; // Add the callback for the default tab. $items["admin/build/pages/edit/%"] = array( - 'title' => t('Edit'), + 'title' => 'Edit', 'page callback' => 'delegator_page_edit_subtask', - 'page arguments' => array(4, $step), + 'page arguments' => array('page', 4, $step), 'type' => MENU_CALLBACK, ) + $base; @@ -68,49 +69,49 @@ function delegator_page_menu(&$items, $task) { $items["admin/build/pages/edit/%/$step"] = array( 'title' => $form_title, 'page callback' => 'delegator_page_edit_subtask', - 'page arguments' => array(4, 5), + 'page arguments' => array('page', 4, 5), 'type' => $type, 'weight' => $weight++, ) + $base; } $items["admin/build/pages/delete/%"] = array( - 'title' => t('Delete'), + 'title' => 'Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('delegator_page_delete_subtask', 4), 'type' => MENU_CALLBACK, ) + $base; $items["admin/build/pages/break-lock/%"] = array( - 'title' => t('Break lock'), + 'title' => 'Break lock', 'page callback' => 'drupal_get_form', 'page arguments' => array('delegator_page_break_lock_subtask', 4), 'type' => MENU_CALLBACK, ) + $base; $items["admin/build/pages/clone/%"] = array( - 'title' => t('Clone'), + 'title' => 'Clone', 'page callback' => 'drupal_get_form', 'page arguments' => array('delegator_page_clone_subtask', 4), 'type' => MENU_CALLBACK, ) + $base; $items["admin/build/pages/export/%"] = array( - 'title' => t('Clone'), + 'title' => 'Export', 'page callback' => 'delegator_page_export_subtask', 'page arguments' => array(4), 'type' => MENU_CALLBACK, ) + $base; $items["admin/build/pages/enable/%"] = array( - 'title' => t('Break lock'), + 'title' => 'Enable', 'page callback' => 'delegator_page_enable_subtask', 'page arguments' => array(4), 'type' => MENU_CALLBACK, ) + $base; $items["admin/build/pages/disable/%"] = array( - 'title' => t('Disable'), + 'title' => 'Disable', 'page callback' => 'delegator_page_disable_subtask', 'page arguments' => array(4), 'type' => MENU_CALLBACK, @@ -230,11 +231,12 @@ function delegator_page_menu_item($task, $menu, $access_arguments, $page_argumen * Get the cached changes to a given task handler. */ function delegator_page_get_page_cache($name) { + // This ensures the task .inc file is loaded + $task = delegator_get_task('page'); + ctools_include('object-cache'); $cache = ctools_object_cache_get('delegator_page', $name); if (!$cache) { - // This ensures the task .inc file is loaded - $task = delegator_get_task('page'); $cache = delegator_page_load($name); } @@ -247,6 +249,9 @@ function delegator_page_get_page_cache($name) { * Store changes to a task handler in the object cache. */ function delegator_page_set_page_cache($page) { + // This ensures the task .inc file is loaded + $task = delegator_get_task('page'); + if (!empty($page->locked)) { return; } @@ -261,6 +266,9 @@ function delegator_page_set_page_cache($page) { * Remove an item from the object cache. */ function delegator_page_clear_page_cache($name) { + // This ensures the task .inc file is loaded + $task = delegator_get_task('page'); + ctools_include('object-cache'); ctools_object_cache_clear('delegator_page', $name); } @@ -320,27 +328,38 @@ function theme_delegator_page_changed() { /** * Page callback to add a subtask. */ -function delegator_page_add_subtask($step = NULL) { - // We load the task to make sure our .inc file is loaded. - $task = delegator_get_task('page'); +function delegator_page_add_subtask($task_name, $step = NULL) { + // We load the 'page' task to make sure our .inc file is loaded. + delegator_get_task('page'); + + $task = delegator_get_task($task_name); + + $function = ctools_plugin_get_function($task, 'form info'); + $form_info = $function(); - $form_info = delegator_page_edit_form_info(); $form_info += array( - 'path' => 'admin/build/pages/add/%step', + 'path' => $form_info['add path'], ); + if (!empty($form_info['add order'])) { + $form_info['order'] = $form_info['add order']; + } + // If step is unset, we're creating a new one. Wipe out our values and start // over. if (!isset($step) || !$page = delegator_page_get_page_cache('::new')) { - $step = 'basic'; - $page = delegator_page_new(); - $page->new = TRUE; + $step = current(array_keys($form_info['order'])); + $page = delegator_page_new(); + $page->task = $task_name; + $page->new = TRUE; + $page->locked = FALSE; delegator_page_set_page_cache($page); } ctools_include('wizard'); $form_state = array( 'cache name' => '::new', + 'task' => $task, 'page' => $page, 'type' => 'add', ); @@ -357,29 +376,38 @@ function delegator_page_add_subtask($step = NULL) { /** * Page callback to add a subtask. */ -function delegator_page_edit_subtask($page_name, $step = NULL) { +function delegator_page_edit_subtask($task_name, $page_name, $step = NULL) { if (!$page = delegator_page_get_page_cache($page_name)) { return drupal_not_found(); } // We load the task to make sure our .inc file is loaded. - $task = delegator_get_task('page'); + $task = delegator_get_task($task_name); + + $function = ctools_plugin_get_function($task, 'form info'); + $form_info = $function(); + $path = str_replace('%page_name', $page_name, $form_info['edit path']); $form_info = array( - 'path' => "admin/build/pages/edit/$page_name/%step", + 'path' => $path, 'show trail' => FALSE, 'show return' => TRUE, 'show cancel' => TRUE, 'return path' => 'admin/build/pages', - ) + delegator_page_edit_form_info(); + ) + $form_info; + + if (!empty($form_info['edit order'])) { + $form_info['order'] = $form_info['edit order']; + } // If step is unset, go with the basic step. if (!isset($step)) { - $step = 'basic'; + $step = current(array_keys($form_info['order'])); } ctools_include('wizard'); $form_state = array( + 'task' => $task, 'cache name' => $page_name, 'page' => $page, 'type' => 'edit', @@ -516,6 +544,10 @@ function delegator_page_form_basic_validate(&$form, &$form_state) { // Ensure path is unused by other pages. $pages = delegator_page_load_all(); $name = !empty($form_state['values']['name']) ? $form_state['values']['name'] : $form_state['page']->name; + if (empty($name)) { + form_error($form['name'], t('Name is required.')); + } + foreach ($pages as $page) { if ($page->name != $name && $page->path == $form_state['values']['path'] && empty($page->disabled)) { form_error($form['path'], t('That path is used by another page: @page', array('@page' => $page->admin_title))); @@ -527,6 +559,12 @@ function delegator_page_form_basic_validate(&$form, &$form_state) { // Replace named placeholders with our own placeholder to load contexts. $path = array(); + if (empty($form_state['values']['path'])) { + form_error($form['path'], t('Path is required.')); + // stop processing here if there is no path. + return; + } + foreach (explode('/', $form_state['values']['path']) as $bit) { if ($bit[0] == '%') { $path[] = '%'; @@ -787,6 +825,7 @@ function delegator_page_form_argument(&$form, &$form_state) { $form['table'] = array( '#theme' => 'delegator_page_form_argument_table', '#delegator-path' => $path, + 'argument' => array(), ); $cache_name = $form_state['cache name']; @@ -1191,7 +1230,7 @@ function delegator_page_argument_form_settings_submit(&$form, &$form_state) { * task handlers. */ function delegator_page_argument_form_multiple(&$form, &$form_state) { - $task = delegator_get_task('page'); + $task = $form_state['task']; $task_handlers = delegator_load_task_handlers($task, $form_state['page']->name); $form['multiple'] = array( @@ -1211,7 +1250,6 @@ function delegator_page_argument_form_multiple(&$form, &$form_state) { $form['multiple']['#description'] .= t('You may not modify this value while multiple task handlers exist. If you wish to change this to single only, you must reduce the number of task handlers attached to the page to zero or one.'); } - $form_state['task'] = $task; $form_state['task_handlers'] = $task_handlers; if ($form_state['type'] == 'add' || empty($task_handlers)) { @@ -1254,9 +1292,10 @@ function delegator_page_argument_form_multiple_submit(&$form, &$form_state) { */ function delegator_page_break_lock_subtask(&$form_state, $name) { // This ensures the task .inc file is loaded - $task = delegator_get_task('page'); + delegator_get_task('page'); $page = delegator_page_load($name); + $form_state['task'] = delegator_get_task($task_name); $form_state['name'] = $name; ctools_include('object-cache'); @@ -1295,7 +1334,9 @@ function delegator_page_break_lock_subtask_submit(&$form, &$form_state) { /** * Import a task handler from cut & paste */ -function delegator_page_import_subtask(&$form_state) { +function delegator_page_import_subtask(&$form_state, $task_name) { + $form_state['task'] = delegator_get_task($task_name); + drupal_set_title(t('Import page')); $form['name'] = array( '#type' => 'textfield', @@ -1380,16 +1421,20 @@ function delegator_page_import_subtask_submit($form, &$form_state) { } delegator_page_set_page_cache($page); - $form_state['redirect'] = 'admin/build/pages/edit/' . $page->name; + $function = ctools_plugin_get_function($form_state['task'], 'form info'); + $form_info = $function(); + + $form_state['redirect'] = str_replace('%page_name/%step', $page->name, $form_info['edit path']); } /** * Entry point to export a page. */ -function delegator_page_export_subtask($name, $handlers = FALSE) { +function delegator_page_export_subtask($task_name, $name, $handlers = FALSE) { // This ensures the task .inc file is loaded - $task = delegator_get_task('page'); + delegator_get_task('page'); $page = delegator_page_load($name); + $form_state['task'] = delegator_get_task($task_name); if (!$page) { return drupal_not_found(); @@ -1411,10 +1456,11 @@ function delegator_page_export_subtask($name, $handlers = FALSE) { /** * Entry point to clone a page. */ -function delegator_page_clone_subtask(&$form_state, $name) { +function delegator_page_clone_subtask(&$form_state, $task_name, $name) { // This ensures the task .inc file is loaded - $form_state['task'] = delegator_get_task('page'); + delegator_get_task('page'); $page = delegator_page_load($name); + $form_state['task'] = delegator_get_task($page->task); if (!$page) { drupal_not_found(); @@ -1489,7 +1535,10 @@ function delegator_page_clone_subtask_submit(&$form, &$form_state) { unset($page->pid); delegator_page_set_page_cache($page); - $form_state['redirect'] = 'admin/build/pages/edit/' . $page->name; + $function = ctools_plugin_get_function($task, 'form info'); + $form_info = $function(); + + $form_state['redirect'] = str_replace('%page_name/%step', $page->name, $form_info['edit path']); } /** * Entry point to enable a page. @@ -1513,9 +1562,8 @@ function delegator_page_disable_subtask($name) { * Entry point to export a page. */ function delegator_page_delete_subtask($form_state, $name) { - // This ensures the task .inc file is loaded - $task = delegator_get_task('page'); $page = delegator_page_get_page_cache($name); + $task = delegator_get_task($page->task); if (!$page) { return drupal_not_found(); diff --git a/delegator/plugins/tasks/page.inc b/delegator/plugins/tasks/page.inc index d5f82082431c3a672ff2fd5a7a085bace6bbb372..b978cfcd1f0573db89c41fab6e09855b0970f647 100644 --- a/delegator/plugins/tasks/page.inc +++ b/delegator/plugins/tasks/page.inc @@ -31,6 +31,7 @@ function delegator_page_delegator_tasks() { 'function' => 'delegator_page_menu', ), 'hook theme' => 'delegator_page_theme', + 'form info' => 'delegator_page_edit_form_info', // page only items 'task type' => 'page', 'operations' => array( @@ -57,6 +58,7 @@ function delegator_page_delegator_tasks() { 'handler type' => 'context', 'get arguments' => 'delegator_page_get_arguments', 'get context placeholders' => 'delegator_page_get_contexts', + 'uses handlers' => TRUE, ), ); } @@ -65,7 +67,7 @@ function delegator_page_delegator_tasks() { * Return a list of all subtasks. */ function delegator_page_subtasks($task) { - $pages = delegator_page_load_all('custom'); + $pages = delegator_page_load_all($task['name']); $return = array(); foreach ($pages as $name => $page) { $return[$name] = delegator_page_build_subtask($task, $page); @@ -88,14 +90,17 @@ function delegator_page_subtask($task, $subtask_id) { * Build a subtask array for a given page. */ function delegator_page_build_subtask($task, $page) { - $form_info = delegator_page_edit_form_info(); + $function = ctools_plugin_get_function($task, 'form info'); + $form_info = $function(); + $edit_links = array(); $name = $page->name; foreach ($form_info['order'] as $form_id => $form_title) { + $edit_links[] = array( 'title' => $form_title, - 'href' => "admin/build/pages/edit/$name/$form_id", + 'href' => str_replace(array('%page_name', '%step'), array($name, $form_id), $form_info['edit path']), ); } @@ -103,35 +108,38 @@ function delegator_page_build_subtask($task, $page) { $task_name = delegator_make_task_name($task['name'], $name); if (empty($page->disabled)) { - if ($page->multiple) { - $operations[] = array( - 'title' => t('Task handlers'), - 'href' => "admin/build/delegator/$task_name", - ); - } - else { - $default_handlers = isset($page->default_handlers) ? $page->default_handlers : array(); - $task_handlers = delegator_load_task_handlers($task, $page->name, $default_handlers); - if ($task_handlers) { - $handler = array_shift($task_handlers); - $plugin = delegator_get_task_handler($handler->handler); - if (!empty($plugin['edit forms'])) { - $actions = array(); - foreach ($plugin['edit forms'] as $edit_id => $title) { - if ($title) { - $actions[] = array( - 'title' => $title, - 'href' => "admin/build/delegator/$task_name/$handler->handler/$handler->name/$edit_id", - ); + if (!empty($task['uses handlers'])) { + if ($page->multiple) { + $operations[] = array( + 'title' => t('Task handlers'), + 'href' => "admin/build/delegator/$task_name", + ); + } + else { + $default_handlers = isset($page->default_handlers) ? $page->default_handlers : array(); + $task_handlers = delegator_load_task_handlers($task, $page->name, $default_handlers); + if ($task_handlers) { + $handler = array_shift($task_handlers); + $plugin = delegator_get_task_handler($handler->handler); + if (!empty($plugin['edit forms'])) { + $actions = array(); + foreach ($plugin['edit forms'] as $edit_id => $title) { + if ($title) { + $actions[] = array( + 'title' => $title, + 'href' => "admin/build/delegator/$task_name/$handler->handler/$handler->name/$edit_id", + ); + } } + $operations[] = array( + 'title' => '<span class="text">' . t('Edit handler') . '</span>' . theme('links', $actions), + 'html' => TRUE, + ); } - $operations[] = array( - 'title' => '<span class="text">' . t('Edit handler') . '</span>' . theme('links', $actions), - 'html' => TRUE, - ); } } } + $operations[] = array( 'title' => '<span class="text">' . t('Edit page') . '</span>' . theme('links', $edit_links), 'html' => TRUE, @@ -144,10 +152,12 @@ function delegator_page_build_subtask($task, $page) { 'title' => t('Export'), 'href' => "admin/build/pages/export/$name", ); - $operations[] = array( - 'title' => t('Export (with handlers)'), - 'href' => "admin/build/pages/export/$name/handlers", - ); + if (!empty($task['has handlers'])) { + $operations[] = array( + 'title' => t('Export (with handlers)'), + 'href' => "admin/build/pages/export/$name/handlers", + ); + } if ($page->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) { $operations[] = array( 'title' => t('Revert'), @@ -173,6 +183,7 @@ function delegator_page_build_subtask($task, $page) { 'href' => "admin/build/pages/enable/$name", ); } + $subtask = array( 'name' => $name, 'admin title' => $page->admin_title, @@ -247,51 +258,16 @@ function delegator_page_edit_form_info() { 'form id' => 'delegator_page_argument_form_multiple', ), ), + // Items specific to the 'add' routines that will get moved over: + 'add path' => 'admin/build/pages/add/%step', + // Items specific to the 'edit' routines that will get moved over: + 'edit path' => 'admin/build/pages/edit/%page_name/%step', ); } // -------------------------------------------------------------------------- // Page execution functions -/** - * Load a context from an argument for a given page task. - * - * @param $value - * The incoming argument value. - * @param $subtask - * The subtask id. - * @param $argument - * The numeric position of the argument in the path, counting from 0. - * - * @return - * A context item if one is configured, the argument if one is not, or - * FALSE if restricted or invalid. - */ -function _dp_arg_load($value, $subtask, $argument) { - $page = delegator_page_load($subtask); - if (!$page) { - return FALSE; - } - - $path = explode('/', $page->path); - if (empty($path[$argument])) { - return FALSE; - } - - $keyword = substr($path[$argument], 1); - if (empty($page->arguments[$keyword])) { - return $value; - } - - $page->arguments[$keyword]['keyword'] = $keyword; - - ctools_include('context'); - $context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value); - - // convert false equivalents to false. - return $context ? $context : FALSE; -} - /** * Execute a page task. * @@ -382,13 +358,13 @@ function delegator_page_load($name) { /** * Load all page subtasks. */ -function delegator_page_load_all($type = NULL) { +function delegator_page_load_all($task = NULL) { ctools_include('export'); - if (empty($type)) { + if (empty($task)) { return ctools_export_load_object('delegator_pages'); } else { - return ctools_export_load_object('delegator_pages', 'conditions', array('type' => $type)); + return ctools_export_load_object('delegator_pages', 'conditions', array('task' => $task)); } } diff --git a/includes/wizard.inc b/includes/wizard.inc index 80862c0f10ceb00fa31c199fdc1d1c950bcbb5f1..dbdd774d233bdcf1298643513c06b164cd0fe0ac 100644 --- a/includes/wizard.inc +++ b/includes/wizard.inc @@ -277,6 +277,10 @@ function ctools_wizard_wrapper(&$form, &$form_state) { if (!empty($form_state['modal'])) { $form['#action'] = url(ctools_wizard_get_path($form_state['form_info'], $form_state['step'])); } + + if (isset($info['wrapper']) && function_exists($info['wrapper'])) { + $info['wrapper']($form, $form_state); + } } /**