You are here

function panels_everywhere_page_build in Panels Everywhere 7

Impleme of hook_theme_registry_alter()

This is the magic of this module, which allows us to completely override how pages are output.

File

./panels_everywhere.module, line 78
panels_everywhere.module

Code

function panels_everywhere_page_build(&$page) {
  if (!panels_everywhere_should_override()) {
    return;
  }
  ctools_include('context');
  ctools_include('context-task-handler');
  $task = page_manager_get_task('site_template');

  // Test to see if something has specified that we use a specific template on
  // this page.
  if ($handler_name = panels_everywhere_get_site_template()) {
    $handler = page_manager_load_task_handler($task, '', $handler_name);
  }

  // If not, ask.
  if (empty($handler)) {
    $handlers = page_manager_load_sorted_handlers($task, '', TRUE);

    // If there are no handlers, don't bother.
    if (!$handlers) {
      return;
    }

    // Normally the args contain the page content, but since this is just
    // choosing the handler not actually rendering it, we'll leave that blank
    // and let the page content be added later.
    $args = array(
      '',
    );
    $contexts = ctools_context_handler_get_task_contexts($task, '', $args);
    $handler_name = ctools_context_handler_get_render_handler($task, '', $handlers, $contexts, $args);
    if ($handler_name) {
      $handler = $handlers[$handler_name];
    }
  }

  // If a handler was selected, change the render method.
  if (!empty($handler)) {
    global $theme;

    // Reset the page theme to use the panels everywhere output instead of the
    // normal page.
    $page['#theme'] = 'panels_everywhere_page';
    $page['#handler'] = $handler;

    // This completely disables blocks on a page without disabling block.module
    // and without going through the extra processor time of building blocks
    // that do not exist.
    // Ensure the list of themes is built.
    $themes = list_themes();

    // Set theme list before overwritten.
    panels_everywhere_set_list_themes_copy($themes);

    // Get the real list so we can modify it.
    $list =& drupal_static('list_themes', array());

    // Clear out the list of regions. Block module will not try to render
    // anything not in this regions list.
    $list[$theme]->info['regions'] = array();
  }
}