You are here

function ctools_context_handler_render in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/context-task-handler.inc \ctools_context_handler_render()

Render a context type task handler given a list of handlers attached to a type.

Parameters

$task: The $task object in use.

$subtask: The id of the subtask in use.

$contexts: The context objects in use.

$args: The raw arguments behind the contexts.

$page: If TRUE then this renderer owns the page and can use theme('page') for no blocks; if false, output is returned regardless of any no blocks settings.

Return value

Either the output or NULL if there was output, FALSE if no handler accepted the task. If $page is FALSE then the $info block is returned instead.

11 calls to ctools_context_handler_render()
page_manager_blog in page_manager/plugins/tasks/blog.inc
Entry point for our overridden node edit.
page_manager_blog_user in page_manager/plugins/tasks/blog_user.inc
Entry point for our overridden user view.
page_manager_contact_site in page_manager/plugins/tasks/contact_site.inc
Entry point for our overridden node edit.
page_manager_contact_user in page_manager/plugins/tasks/contact_user.inc
Entry point for our overridden user view.
page_manager_node_edit in page_manager/plugins/tasks/node_edit.inc
Entry point for our overridden node edit.

... See full list

File

includes/context-task-handler.inc, line 38
Support for creating 'context' type task handlers.

Code

function ctools_context_handler_render($task, $subtask, $contexts, $args, $page = TRUE) {

  // Load the landlers, choosing only enabled handlers.
  $handlers = page_manager_load_sorted_handlers($task, $subtask ? $subtask['name'] : '', TRUE);

  // Try each handler.
  foreach ($handlers as $handler) {
    if ($function = page_manager_get_renderer($handler)) {
      if ($info = $function($handler, $contexts, $args)) {
        drupal_alter('ctools_render', $info, $page, $args, $contexts, $task, $subtask, $handler);

        // If we don't own the page, let the caller deal with rendering.
        if (!$page) {
          return $info;
        }
        if ($subtask) {
          $task_name = page_manager_make_task_name($task['name'], $subtask['name']);
        }
        else {
          $task_name = $task['name'];
        }
        page_manager_get_current_page(array(
          'name' => $task_name,
          'task' => $task,
          'subtask' => $subtask,
          'contexts' => $contexts,
          'arguments' => $args,
          'handler' => $handler,
        ));
        if (!empty($info['response code']) && $info['response code'] != 200) {
          switch ($info['response code']) {
            case 403:
              return MENU_ACCESS_DENIED;
            case 404:
              return MENU_NOT_FOUND;
            case 301:
            case 302:
            case 303:
            case 304:
            case 305:
            case 307:
              $info += array(
                'query' => '',
                'fragment' => '',
              );
              return drupal_goto($info['destination'], $info['query'], $info['fragment'], $info['response code']);
          }
        }

        /*
        // Only do this if something hasn't already changed the active menu,
        // such as a book.
        if (menu_get_active_menu_name() == 'navigation') {
          $item = menu_get_item();
          $mlink = db_fetch_object(db_query("SELECT * FROM {menu_links} WHERE link_path = '%s'", $item['href']));

          if ($mlink && isset($mlink->menu_name)) {
            menu_set_active_menu_name($mlink->menu_name);
          }
        }
        */
        foreach (ctools_context_handler_get_task_arguments($task, $subtask) as $id => $argument) {
          $plugin = ctools_get_argument($argument['name']);
          $cid = ctools_context_id($argument, 'argument');
          if (!empty($contexts[$cid]) && ($function = ctools_plugin_get_function($plugin, 'breadcrumb'))) {
            $function($argument['settings'], $contexts[$cid]);
          }
        }
        if (isset($info['title'])) {
          drupal_set_title($info['title']);
        }

        // Only directly output if $page was set to true.
        if (!empty($info['no_blocks'])) {
          print theme('page', $info['content'], FALSE);
          return;
        }
        else {
          return $info['content'];
        }
      }
    }
  }
  return FALSE;
}