You are here

function panels_everywhere_page_preprocess in Panels Everywhere 6

Page preprocess to run the page content into our site template task.

This is NOT named by the normal rules because this is not picked up automatically. It is controlled by an alter so that it can come first.

1 string reference to 'panels_everywhere_page_preprocess'
panels_everywhere_theme_registry_alter in ./panels_everywhere.module
Implementation of hook_theme_registry_alter()

File

./panels_everywhere.module, line 150
panels_everywhere.module

Code

function panels_everywhere_page_preprocess(&$vars) {

  // For safety reasons, do not run this on the actual page configuration pages
  // and instead allow a more traditional output.
  if (strpos($_GET['q'], 'admin/build/pages/nojs/operation/site_template') === 0) {
    return panels_everywhere_fallback_page($vars);
  }
  if (strncmp($_GET['q'], 'admin/build/pages/site_template', 21) == 0) {
    return panels_everywhere_fallback_page($vars);
  }
  $task = page_manager_get_task('site_template');
  $content = new stdClass();
  $content->title = drupal_get_title();
  $content->content = $vars['content'];

  // Load the node into a context.
  ctools_include('context');
  ctools_include('context-task-handler');
  $page = page_manager_get_current_page();
  if (version_compare(CTOOLS_API_VERSION, 1.8, '<')) {
    $args = array(
      $_GET['q'],
      $content,
      $page,
    );
  }
  else {
    $args = array(
      $content,
    );
  }
  $contexts = ctools_context_handler_get_task_contexts($task, '', $args);

  // Test to see if a site template has been specifically assigned to the
  // current page. If so, render that variant just as though it were rendered
  // by the access checker.
  if ($handler_name = panels_everywhere_get_site_template()) {

    // This is the "no template" variant meaning we do absolutely nothing here.
    if ($handler_name == -1) {
      return;
    }
    $handler = page_manager_load_task_handler($task, '', $handler_name);
    if ($handler && ($function = page_manager_get_renderer($handler))) {

      // Render this with $test == FALSE to make it skip access checking.
      if ($info = $function($handler, $contexts, $args, FALSE)) {
        drupal_alter('ctools_render', $info, $page, $args, $contexts, $task, '', $handler);
      }
    }
  }

  // If there is no $info, meaning the above had no template or the template
  // chose not to render, go through the normal process for finding one.
  if (empty($info)) {

    // Since we're inside theme('page') we must call
    // ctools_context_handler_render as though we don't own the page, because
    // crazy as it sounds, we don't.
    $info = ctools_context_handler_render($task, '', $contexts, $args, FALSE);
  }
  if ($info && !empty($info['content'])) {

    // Because we run so early, we have to use drupal_set_title() and not just
    // set $vars['title']. Otherwise it will get overwritten.
    if (isset($info['title'])) {
      drupal_set_title($info['title']);
    }
    $vars['content'] = $info['content'];
    if (!empty($info['no_blocks'])) {
      $vars['show_blocks'] = FALSE;
    }
    $vars['panels_everywhere_site_template'] = array(
      'name' => 'site_template',
      'task' => $task,
      'subtask' => '',
      'contexts' => $contexts,
      'arguments' => $args,
      'handler' => $info['handler'],
    );
  }
}