You are here

function esi_panels__restore_context in ESI: Edge Side Includes 7.3

Restore the original context that was used when a block was displayed.

1 call to esi_panels__restore_context()
esi_panels__esi_pane_prepare in modules/esi_panels/esi_panels.esi.inc
Prepare an ESI panels pane for rendering. Defined in hook_esi_component_info().

File

modules/esi_panels/esi_panels.esi.inc, line 85

Code

function esi_panels__restore_context(&$pane) {

  // Restore the theme.
  global $theme;
  $theme = $pane->esi_meta['theme'];
  $_GET['q'] = $pane->esi_meta['url'];
  $_SERVER['REQUEST_URI'] = $pane->esi_meta['url'];
  drupal_static_reset('drupal_get_destination');

  // Load up contexts. Owch.
  if (!empty($pane->configuration['context'])) {
    ctools_include('context');
    ctools_include('context-task-handler');

    // Load the task/subtask plugins.
    $task = page_manager_get_task($pane->esi_meta['task']);
    $subtask = empty($pane->esi_meta['subtask']) ? '' : page_manager_get_task_subtask($task, $pane->esi_meta['subtask']);

    // Use the task-name and the original display arguments to generate the
    // arguments that were passed to the context constructor.
    // E.g. The node_view task takes "1" and returns node_load(1).
    $base_context_arguments = esi_panels__get_base_context_arguments($pane->esi_meta['task'], $pane->esi_meta['subtask'], $pane->esi_meta['display_args']);
    $base_contexts = ctools_context_handler_get_task_contexts($task, $subtask, $base_context_arguments);

    // The base contexts are then typically used in the task plugin as render
    // information:
    // $output = ctools_context_handler_render($task, '', $contexts, array($node->nid));
    // Other contexts are usually loaded by the panel_context task_handler
    // plugin in the render function panels_panel_context_render():
    // $contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);
    // Load the relevant handler
    $contexts = array();
    $handlers = page_manager_load_sorted_handlers($task, $subtask ? $subtask['name'] : '', TRUE);
    $id = ctools_context_handler_get_render_handler($task, $subtask, $handlers, $base_contexts, $pane->esi_meta['display_args']);
    if ($id) {
      $handler = $handlers[$id];
      $contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);
    }
    $pane->esi_meta['display_contexts'] = $contexts;
  }
}