View source
<?php
function quiz_quiztake_page_manager_tasks() {
return array(
'task type' => 'page',
'title' => t('Take @quiz', array(
'@quiz' => QUIZ_NAME,
)),
'admin title' => t('The take page for @quiz.', array(
'@quiz' => QUIZ_NAME,
)),
'admin description' => t('When enabled, this overrides the default view at node/%node/take'),
'admin path' => 'node/%node/take',
'hook menu alter' => 'quiz_quiztake_menu_alter',
'handler type' => 'context',
'get arguments' => 'quiz_quiztake_get_arguments',
'get context placeholders' => 'quiz_quiztake_get_contexts',
'disabled' => variable_get('quiz_quiztake_disabled', TRUE),
'enable callback' => 'quiz_quiztake_enable',
);
}
function quiz_quiztake_menu_alter(&$items, $task) {
if (variable_get('quiz_quiztake_disabled', TRUE)) {
return;
}
$callback = $items['node/%node/take']['page callback'];
if ($callback == 'quiz_take' || variable_get('page_manager_override_anyway', FALSE)) {
$items['node/%node/take']['page callback'] = 'quiz_quiztake';
$items['node/%node/take']['file path'] = $task['path'];
$items['node/%node/take']['file'] = $task['file'];
}
else {
if (!empty($GLOBALS['page_manager_enabling_quiz'])) {
drupal_set_message(t('Page manager module is unable to enable Qui take Node because some other module already has overridden with %callback.', array(
'%callback' => $callback,
)), 'warning');
}
return;
}
}
function quiz_quiztake($node) {
$task = page_manager_get_task('quiztake');
ctools_include('context');
ctools_include('context-task-handler');
$contexts = ctools_context_handler_get_task_contexts($task, '', array(
$node,
));
$output = ctools_context_handler_render($task, '', $contexts, array(
$node->nid,
));
if ($output !== FALSE) {
return $output;
}
module_load_include('inc', 'quiz', 'quiz.node');
$function = 'quiz_take';
foreach (module_implements('page_manager_override') as $module) {
$call = $module . '_page_manager_override';
if (($rc = $call('quiz')) && function_exists($rc)) {
$function = $rc;
break;
}
}
return $function($node);
}
function quiz_quiztake_enable($cache, $status) {
variable_set('quiz_quiztake_disabled', $status);
if (!$status) {
$GLOBALS['page_manager_enabling_quiz'] = TRUE;
}
}
function quiz_quiztake_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'node',
'identifier' => t('Node being taken'),
'id' => 1,
'name' => 'entity_id:node',
'settings' => array(),
),
);
}
function quiz_quiztake_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(page_manager_node_view_get_arguments($task, $subtask_id));
}