You are here

function panels_panel_context_render in Panels 7.3

Same name and namespace in other branches
  1. 6.3 plugins/task_handlers/panel_context.inc \panels_panel_context_render()

Check selection rules and, if passed, render the contexts.

1 string reference to 'panels_panel_context_render'
panel_context.inc in plugins/task_handlers/panel_context.inc
This is the task handler plugin to handle attaching a panel to any task that advertises itself as a 'context' type, which all of the basic page tasks provided by page_manager.module do by default.

File

plugins/task_handlers/panel_context.inc, line 265
This is the task handler plugin to handle attaching a panel to any task that advertises itself as a 'context' type, which all of the basic page tasks provided by page_manager.module do by default.

Code

function panels_panel_context_render($handler, $base_contexts, $args, $test = TRUE) {

  // Go through arguments and see if they match.
  ctools_include('context');
  ctools_include('context-task-handler');
  ctools_include('plugins', 'panels');

  // Add my contexts.
  $contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);

  // Test.
  if ($test && !ctools_context_handler_select($handler, $contexts)) {
    return;
  }
  if (isset($handler->handler)) {
    ctools_context_handler_pre_render($handler, $contexts, $args);
  }

  // Load the display.
  $display = panels_panel_context_get_display($handler);
  $display->context = $contexts;
  $display->args = $args;
  $page_css_id = ctools_context_keyword_substitute($handler->conf['css_id'], array(), $contexts);
  $display->css_id = check_plain($page_css_id);
  $task_name = page_manager_make_task_name($handler->task, $handler->subtask);
  $display->cache_key = panels_panel_context_cache_key($task_name, $handler->name, $args);

  // Check to see if there is any CSS.
  if (!empty($handler->conf['css'])) {
    ctools_include('css');
    $css_id = 'panel_context:' . $handler->name;
    $filename = ctools_css_retrieve($css_id);
    if (!$filename) {

      // Add keywords from context.
      $css = ctools_context_keyword_substitute($handler->conf['css'], array(), $contexts, array(
        'css safe' => TRUE,
      ));
      $filename = ctools_css_store($css_id, $css);
    }
    drupal_add_css($filename);
  }

  // With an argument, this actually sets the display.
  panels_get_current_page_display($display);
  $renderer = panels_get_renderer($handler->conf['pipeline'], $display);

  // If the IPE is enabled, but the user does not have access to edit
  // load the standard renderer instead.
  $parents = class_parents($renderer);
  if (!empty($parents['panels_renderer_editor']) && !user_access('user page manager') && !user_access('use ipe with page manager')) {
    $renderer = panels_get_renderer_handler('standard', $display);
  }

  // Remove and add body element classes.
  $panel_body_css =& drupal_static('panel_body_css', array());
  if (isset($handler->conf['body_classes_to_remove'])) {
    $classes = ctools_context_keyword_substitute($handler->conf['body_classes_to_remove'], array(), $contexts, array(
      'css safe' => TRUE,
    ));
    if (!isset($panel_body_css['body_classes_to_remove'])) {
      $panel_body_css['body_classes_to_remove'] = check_plain($classes);
    }
    else {
      $panel_body_css['body_classes_to_remove'] .= ' ' . check_plain($classes);
    }
  }
  if (isset($handler->conf['body_classes_to_add'])) {
    $classes = ctools_context_keyword_substitute($handler->conf['body_classes_to_add'], array(), $contexts, array(
      'css safe' => TRUE,
    ));
    if (!isset($panel_body_css['body_classes_to_add'])) {
      $panel_body_css['body_classes_to_add'] = check_plain($classes);
    }
    else {
      $panel_body_css['body_classes_to_add'] .= ' ' . check_plain($classes);
    }
  }
  $info = array(
    'content' => panels_render_display($display, $renderer),
    'no_blocks' => !empty($handler->conf['no_blocks']),
  );
  $info['title'] = $display
    ->get_title();
  return $info;
}