From 22f2db89d252239d3942a6918eca5fed6cf71776 Mon Sep 17 00:00:00 2001 From: Earl Miles <merlin@logrus.com> Date: Tue, 28 Apr 2009 20:37:06 +0000 Subject: [PATCH] Updates and fixes to support the Panels D5 -> D6 upgrade path. --- delegator/delegator.admin.inc | 40 ---------------- delegator/delegator.module | 42 +++++++++++++++- delegator/plugins/tasks/node_edit.inc | 4 +- delegator/plugins/tasks/node_view.inc | 4 +- delegator/plugins/tasks/page.inc | 9 +++- delegator/plugins/tasks/term_view.inc | 48 +++++++++++++++---- delegator/plugins/tasks/user_view.inc | 4 +- includes/context-task-handler.inc | 6 ++- includes/context.inc | 6 +-- views_content/plugins/content_types/views.inc | 24 +++++++++- 10 files changed, 124 insertions(+), 63 deletions(-) diff --git a/delegator/delegator.admin.inc b/delegator/delegator.admin.inc index b9a42e01..47961065 100644 --- a/delegator/delegator.admin.inc +++ b/delegator/delegator.admin.inc @@ -26,46 +26,6 @@ define('DGA_CHANGED_DELETED', 0x04); */ define('DGA_CHANGED_STATUS', 0x08); -/** - * Reset the active menu trail to the trail specified by the task type. - * - * The task type can specify an 'admin path'. If it does, - * 'admin/build/delegator' will be removed from the active trail and replaced - * with whatever is in the admin path; that way task types can provide - * their own administration. - */ -function delegator_set_trail($task, $task_name = NULL) { - $task_type = delegator_get_task_type($task['task type']); - if (empty($task_type['admin path'])) { - return; - } - - - ctools_include('menu'); - $trail = menu_get_active_trail(); - $remove = ctools_get_menu_trail('admin/build/delegator'); - foreach ($remove as $info) { - foreach ($trail as $id => $crumb) { - if ($crumb['href'] == $info['href']) { - unset($trail[$id]); - } - } - } - - if ($task_name) { - // Clean up broken 'Edit' link that Drupal leaves behind. - $trail = array_values($trail); - if (isset($trail[0]) && $trail[0]['title'] == t('Edit')) { - unset($trail[0]); - } - - array_unshift($trail, menu_get_item('admin/build/delegator/' . $task_name)); - } - - $trail = array_merge(ctools_get_menu_trail($task_type['admin path']), $trail); - menu_set_active_trail($trail); -} - /** * Get the cached changes to a group of task handlers for * a given task. diff --git a/delegator/delegator.module b/delegator/delegator.module index badd7fd0..46a92d61 100644 --- a/delegator/delegator.module +++ b/delegator/delegator.module @@ -406,7 +406,7 @@ function delegator_save_task_handler(&$handler) { // If this was previously a default handler, we may have to write task handlers. if (!$update) { - + // @todo wtf was I going to do here? } return $handler; } @@ -822,3 +822,43 @@ function _dp_arg_load($value, $subtask, $argument) { // convert false equivalents to false. return $context ? $context : FALSE; } + +/** + * Reset the active menu trail to the trail specified by the task type. + * + * The task type can specify an 'admin path'. If it does, + * 'admin/build/delegator' will be removed from the active trail and replaced + * with whatever is in the admin path; that way task types can provide + * their own administration. + */ +function delegator_set_trail($task, $task_name = NULL) { + $task_type = delegator_get_task_type($task['task type']); + if (empty($task_type['admin path'])) { + return; + } + + + ctools_include('menu'); + $trail = menu_get_active_trail(); + $remove = ctools_get_menu_trail('admin/build/delegator'); + foreach ($remove as $info) { + foreach ($trail as $id => $crumb) { + if ($crumb['href'] == $info['href']) { + unset($trail[$id]); + } + } + } + + if ($task_name) { + // Clean up broken 'Edit' link that Drupal leaves behind. + $trail = array_values($trail); + if (isset($trail[0]) && $trail[0]['title'] == t('Edit')) { + unset($trail[0]); + } + + array_unshift($trail, menu_get_item('admin/build/delegator/' . $task_name)); + } + + $trail = array_merge(ctools_get_menu_trail($task_type['admin path']), $trail); + menu_set_active_trail($trail); +} diff --git a/delegator/plugins/tasks/node_edit.inc b/delegator/plugins/tasks/node_edit.inc index 32078c6f..9689819a 100644 --- a/delegator/plugins/tasks/node_edit.inc +++ b/delegator/plugins/tasks/node_edit.inc @@ -73,7 +73,7 @@ function delegator_node_edit($node) { ctools_include('context-task-handler'); $contexts = ctools_context_handler_get_task_contexts($task, '', array($node)); - $output = ctools_context_handler_render($task, '', $contexts); + $output = ctools_context_handler_render($task, '', $contexts, array($node->nid)); if ($output === FALSE) { // Fall back! // We've already built the form with the context, so we can't build it again, or @@ -122,7 +122,7 @@ function delegator_node_edit_get_arguments($task, $subtask_id) { array( 'keyword' => 'node', 'identifier' => t('Node being edited'), - 'id' => 0, + 'id' => 1, 'name' => 'node_edit', 'settings' => array(), ), diff --git a/delegator/plugins/tasks/node_view.inc b/delegator/plugins/tasks/node_view.inc index 1081c31d..4ec25dae 100644 --- a/delegator/plugins/tasks/node_view.inc +++ b/delegator/plugins/tasks/node_view.inc @@ -70,7 +70,7 @@ function delegator_node_view($node) { ctools_include('context-task-handler'); $contexts = ctools_context_handler_get_task_contexts($task, '', array($node)); - $output = ctools_context_handler_render($task, '', $contexts); + $output = ctools_context_handler_render($task, '', $contexts, array($node->nid)); if ($output !== FALSE) { node_tag_new($node->nid); return $output; @@ -91,7 +91,7 @@ function delegator_node_view_get_arguments($task, $subtask_id) { array( 'keyword' => 'node', 'identifier' => t('Node being viewed'), - 'id' => 0, + 'id' => 1, 'name' => 'nid', 'settings' => array(), ), diff --git a/delegator/plugins/tasks/page.inc b/delegator/plugins/tasks/page.inc index 158d469e..6375125c 100644 --- a/delegator/plugins/tasks/page.inc +++ b/delegator/plugins/tasks/page.inc @@ -294,14 +294,19 @@ function delegator_page_execute($subtask_id) { // Turn the contexts into a properly keyed array. $contexts = array(); - foreach (func_get_args() as $arg) { + $args = array(); + foreach (func_get_args() as $count => $arg) { if (is_object($arg) && get_class($arg) == 'ctools_context') { $contexts[$arg->id] = $arg; + $args[] = $arg->original_argument; + } + else if ($count) { + $args[] = $arg; } } ctools_include('context-task-handler'); - $output = ctools_context_handler_render($task, $subtask_id, $contexts); + $output = ctools_context_handler_render($task, $subtask_id, $contexts, $args); if ($output === FALSE) { return drupal_not_found(); } diff --git a/delegator/plugins/tasks/term_view.inc b/delegator/plugins/tasks/term_view.inc index 19e30b60..fc3525fe 100644 --- a/delegator/plugins/tasks/term_view.inc +++ b/delegator/plugins/tasks/term_view.inc @@ -42,17 +42,29 @@ function delegator_term_view_delegator_tasks() { 'title' => t('Task handlers'), 'href' => "admin/build/delegator/term_view", ), -/* array( 'title' => t('Settings'), 'href' => "admin/build/delegator/term_view/settings", ), -*/ ), ), ); } +/** + * Create the term view settings page menu item. + */ +function delegator_term_view_menu(&$items, $task) { + $items['admin/build/delegator/term_view/settings'] = array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('delegator_term_view_settings'), + 'file path' => $task['path'], + 'file' => $task['file'], + 'access arguments' => array('administer delegator'), + 'type' => MENU_CALLBACK, + ); +} + /** * Callback defined by delegator_term_view_delegator_tasks(). * @@ -84,8 +96,11 @@ function delegator_term_view($terms, $depth = 0, $op = 'page') { ctools_include('context'); ctools_include('context-task-handler'); $contexts = ctools_context_handler_get_task_contexts($task, '', array($terms, $depth)); + if (empty($contexts)) { + return drupal_not_found(); + } - $output = ctools_context_handler_render($task, '', $contexts); + $output = ctools_context_handler_render($task, '', $contexts, array($terms, $depth, $op)); if ($output !== FALSE) { return $output; } @@ -106,15 +121,16 @@ function delegator_term_view_get_arguments($task, $subtask_id) { return array( array( 'keyword' => 'term', - 'identifier' => t('Term(s) being viewed'), - 'id' => 0, - 'name' => 'terms', - 'settings' => array(), + 'identifier' => variable_get('delegator_term_view_type', 'multiple') == 'multiple' ? t('Term(s) being viewed') : t('Term being viewed'), + 'id' => 1, + 'name' => variable_get('delegator_term_view_type', 'multiple') == 'multiple' ? 'terms' : 'term', + 'settings' => array('input_form' => 'tid'), + 'default' => '404', ), array( 'keyword' => 'depth', 'identifier' => t('Depth'), - 'id' => 0, + 'id' => 1, 'name' => 'string', 'settings' => array(), ), @@ -128,3 +144,19 @@ function delegator_term_view_get_contexts($task, $subtask_id) { return ctools_context_get_placeholders_from_argument(delegator_term_view_get_arguments($task, $subtask_id)); } +/** + * Settings page for this item. + */ +function delegator_term_view_settings() { + $task = delegator_get_task('term_view'); + delegator_set_trail($task); + $form['delegator_term_view_type'] = array( + '#type' => 'radios', + '#title' => t('Allow multiple terms'), + '#options' => array('single' => t('Single term'), 'multiple' => t('Multiple terms')), + '#description' => t('By default, Drupal allows multiple terms as an argument by separating them with commas or plus signs. If you set this to single, that feature will be disabled.'), + '#default_value' => variable_get('delegator_term_view_type', 'multiple'), + ); + + return system_settings_form($form); +} diff --git a/delegator/plugins/tasks/user_view.inc b/delegator/plugins/tasks/user_view.inc index 9d128a2d..0dab03bf 100644 --- a/delegator/plugins/tasks/user_view.inc +++ b/delegator/plugins/tasks/user_view.inc @@ -55,7 +55,7 @@ function delegator_user_view($account) { ctools_include('context-task-handler'); $contexts = ctools_context_handler_get_task_contexts($task, '', array($account)); - $output = ctools_context_handler_render($task, '', $contexts); + $output = ctools_context_handler_render($task, '', $contexts, array($account->uid)); if ($output === FALSE) { // Fall back! module_load_include('inc', 'user', 'user.pages'); @@ -76,7 +76,7 @@ function delegator_user_view_get_arguments($task, $subtask_id) { array( 'keyword' => 'user', 'identifier' => t('User being viewed'), - 'id' => 0, + 'id' => 1, 'name' => 'uid', 'settings' => array(), ), diff --git a/includes/context-task-handler.inc b/includes/context-task-handler.inc index 5c5053e1..34b2f2c1 100644 --- a/includes/context-task-handler.inc +++ b/includes/context-task-handler.inc @@ -26,6 +26,8 @@ * The id of the subtask in use. * @param $contexts * The context objects in use. + * @param $args + * The raw arguments behind the contexts. * @param $page * If TRUE then this renderer owns the page and can use theme('page') * for no blocks; if false, output is returned regardless of any no @@ -34,14 +36,14 @@ * Either the output or NULL if there was output, FALSE if no handler * accepted the task. If $page is FALSE then the $info block is returned instead. */ -function ctools_context_handler_render($task, $subtask_id, $contexts, $page = TRUE) { +function ctools_context_handler_render($task, $subtask_id, $contexts, $args, $page = TRUE) { // Load the landlers, choosing only enabled handlers. $handlers = delegator_load_sorted_handlers($task, $subtask_id, TRUE); // Try each handler. foreach ($handlers as $handler) { if ($function = delegator_get_renderer($handler)) { - if ($info = $function($handler, $contexts)) { + if ($info = $function($handler, $contexts, $args)) { // If we don't own the page, let the caller deal with rendering. if (!$page) { return $info; diff --git a/includes/context.inc b/includes/context.inc index 7288dca4..d58ef4ba 100644 --- a/includes/context.inc +++ b/includes/context.inc @@ -741,7 +741,7 @@ function ctools_context_get_context_from_arguments($arguments, &$contexts, $args $context = $contexts[$id]; } - if ((empty($context) || empty($context->data)) && $argument['default'] == '404') { + if ((empty($context) || empty($context->data)) && !empty($argument['default']) && $argument['default'] == '404') { return FALSE; } } @@ -1148,8 +1148,8 @@ function ctools_context_replace_form(&$form, $contexts) { $info = $context->placeholder['conf']; $plugin = ctools_get_argument($info['name']); $settings = $info['settings']; - break; + case 'context': $info = $context->placeholder['conf']; $plugin = ctools_get_context($info['name']); @@ -1163,7 +1163,7 @@ function ctools_context_replace_form(&$form, $contexts) { $form[$cid] = $plugin['placeholder form']; } else if (function_exists($plugin['placeholder form'])) { - $widget = $plugin['placeholder form']($argument['settings']); + $widget = $plugin['placeholder form']($info['settings']); if ($widget) { $form[$cid] = $widget; } diff --git a/views_content/plugins/content_types/views.inc b/views_content/plugins/content_types/views.inc index 33dbb7b8..8a9c535f 100644 --- a/views_content/plugins/content_types/views.inc +++ b/views_content/plugins/content_types/views.inc @@ -105,6 +105,8 @@ function _views_content_views_content_type($view) { * Outputs a view based on the module and delta supplied in the configuration. */ function views_content_views_content_type_render($subtype, $conf, $panel_args, $contexts) { + _views_content_views_update_conf($conf, views_content_views_ctools_content_types()); + if (!is_array($contexts)) { $contexts = array($contexts); } @@ -115,7 +117,7 @@ function views_content_views_content_type_render($subtype, $conf, $panel_args, $ } else { $view = views_get_view($subtype); - $display = $conf['display']; + $display = isset($conf['display']) ? $conf['display'] : 'default'; } if (empty($view)) { @@ -245,6 +247,7 @@ function views_content_views_select_display_submit(&$form, &$form_state) { */ function views_content_views_content_type_edit_form(&$form, &$form_state) { $conf = $form_state['conf']; + _views_content_views_update_conf($conf, views_content_views_ctools_content_types()); // This allows older content to continue to work, where we used to embed // the display directly. if (strpos($form_state['subtype_name'], '-')) { @@ -381,11 +384,13 @@ function views_content_views_content_type_edit_form_submit(&$form, &$form_state) * Returns the administrative title for a type. */ function views_content_views_content_type_admin_title($subtype, $conf) { + _views_content_views_update_conf($conf, views_content_views_ctools_content_types()); if (strpos($subtype, '-')) { list($name, $display) = explode('-', $subtype); $view = views_get_view($name); } else { + $name = $subtype; $view = views_get_view($subtype); } @@ -399,12 +404,14 @@ function views_content_views_content_type_admin_title($subtype, $conf) { * Returns the administrative title for a type. */ function views_content_views_content_type_admin_info($subtype, $conf, $contexts) { + _views_content_views_update_conf($conf, views_content_views_ctools_content_types()); if (strpos($subtype, '-')) { list($name, $conf['display']) = explode('-', $subtype); $view = views_get_view($name); } else { $view = views_get_view($subtype); + $name = $subtype; } if (empty($view)) { @@ -474,3 +481,18 @@ function views_content_views_content_type_admin_info($subtype, $conf, $contexts) $view->destroy(); return $block; } + +/** + * Update the $conf to deal with updates from Drupal 5. + */ +function _views_content_views_update_conf(&$conf, $task) { + if (isset($conf['display'])) { + return; + } + $conf['display'] = 'default'; + foreach ($task['defaults'] as $key => $value) { + if (!isset($conf[$key])) { + $conf[$key] = $value; + } + } +} \ No newline at end of file -- GitLab