function ctools_context_handler_render_handler in Chaos Tool Suite (ctools) 7
Render a task handler.
1 call to ctools_context_handler_render_handler()
- ctools_context_handler_render in includes/
context-task-handler.inc - Render a context type task handler given a list of handlers attached to a type.
File
- includes/
context-task-handler.inc, line 98 - Support for creating 'context' type task handlers.
Code
function ctools_context_handler_render_handler($task, $subtask, $handler, $contexts, $args, $page = TRUE) {
$function = page_manager_get_renderer($handler);
if (!$function) {
return NULL;
}
if ($page) {
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,
));
}
$info = $function($handler, $contexts, $args);
if (!$info) {
return NULL;
}
$context = array(
'args' => $args,
'contexts' => $contexts,
'task' => $task,
'subtask' => $subtask,
'handler' => $handler,
);
drupal_alter('ctools_render', $info, $page, $context);
// If we don't own the page, let the caller deal with rendering.
if (!$page) {
return $info;
}
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 410:
drupal_add_http_header('Status', '410 Gone');
drupal_exit();
break;
case 301:
case 302:
case 303:
case 304:
case 305:
case 307:
$info += array(
'query' => array(),
'fragment' => '',
);
$options = array(
'query' => $info['query'],
'fragment' => $info['fragment'],
);
drupal_goto($info['destination'], $options, $info['response code']);
}
}
$plugin = page_manager_get_task_handler($handler->handler);
if (module_exists('contextual') && user_access('access contextual links') && isset($handler->task)) {
// Provide a contextual link to edit this, if we can:
$callback = isset($plugin['contextual link']) ? $plugin['contextual link'] : 'ctools_task_handler_default_contextual_link';
if ($callback && function_exists($callback)) {
$links = $callback($handler, $plugin, $contexts, $args);
}
if (!empty($links) && is_array($links)) {
$build = array(
'#theme_wrappers' => array(
'container',
),
'#attributes' => array(
'class' => array(
'contextual-links-region',
),
),
);
if (!is_array($info['content'])) {
$build['content']['#markup'] = $info['content'];
}
else {
$build['content'] = $info['content'];
}
$build['contextual_links'] = array(
'#prefix' => '<div class="contextual-links-wrapper">',
'#suffix' => '</div>',
'#theme' => 'links__contextual',
'#links' => $links,
'#attributes' => array(
'class' => array(
'contextual-links',
),
),
'#attached' => array(
'library' => array(
array(
'contextual',
'contextual-links',
),
),
),
);
$info['content'] = $build;
}
}
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'], PASS_THROUGH);
}
// Only directly output if $page was set to true.
if (!empty($info['no_blocks'])) {
ctools_set_no_blocks(FALSE);
}
return $info['content'];
}