1

The Panels Ajax Tab module is loading panes (minipanel pane) on panel pages via Ajax:

$pane = panels_mini_block_view($name);
echo $pane['content'];

This will get the contexts defined on the minipanel. What I would like to have is the context that is defined on the host Panel page. I have a working solution for page manager pages, where context is 'static', so there is no argument but everything is fixed. The solution is ugly but works:

inject_panels_page_context($page_name);
$pane = panels_mini_block_view($name);
echo $pane['content'];

function inject_panels_page_context($subtask_id) {
  ctools_include('page', 'page_manager', 'plugins/tasks');
  $page = page_manager_page_load($subtask_id);
  $task = page_manager_get_task($page->task);
  $subtask = page_manager_get_task_subtask($task, $subtask_id);

  // Turn the contexts into a properly keyed array.
  $contexts = array();
  $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;
    }
  }

  $count = 0;
  $names = page_manager_page_get_named_arguments($page->path);
  $bits = explode('/', $page->path);

  if ($page->arguments) {
    foreach ($page->arguments as $name => $argument) {
      // Optional arguments must be converted to contexts too, if they exist.
      if ($bits[$names[$name]][0] == '!') {
        ctools_include('context');
        $argument['keyword'] = $name;
        if (isset($args[$count])) {
          // Hack: use a special argument config variable to learn if we need
          // to use menu_tail style behavior:
          if (empty($argument['settings']['use_tail'])) {
            $value = $args[$count];
          }
          else {
            $value = implode('/', array_slice($args, $count));
          }

          $context = ctools_context_get_context_from_argument($argument, $value);
        }
        else {
          // make sure there is a placeholder context for missing optional contexts.
          $context = ctools_context_get_context_from_argument($argument, NULL, TRUE);
          // Force the title to blank for replacements
        }
        if ($context) {
          $contexts[$context->id] = $context;
        }
      }
      $count++;
    }
  }

  ctools_include('context-task-handler');
  ctools_include('context');

  $handlers = page_manager_load_sorted_handlers($task, $subtask ? $subtask['name'] : '', TRUE);
  $handler = $handlers['page_' . $subtask_id . '_panel_context'];
  $contexts_all = ctools_context_handler_get_handler_contexts($contexts, $handler);

  $current_page_ = page_manager_get_current_page();
  $current_page_['contexts'] = $contexts_all;
  page_manager_get_current_page($current_page_);
}

But this is still not collecting context that is using arguments, such as the current node (on the node_view panels page) or current user account (on user_view page). Those arguments are defined in ctools/page_manager/plugins/tasks - each of them separately.

What would be the preferred way of collecting all contexts, including, contexts with arguments and added contexts? Is there a cache that could be used?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.