'page',
'title' => t('Comment reply'),
'description' => t('The Comment reply task allows you to control what handler will handle the job of rendering a Comment reply at the path comment/reply/%node. If no handler is set or matches the criteria, the default Drupal node renderer will be used.'),
'admin title' => 'Comment reply', // translated by menu system
'admin description' => 'Overrides for the built in Comment reply handler at comment/reply/%node.',
'admin path' => 'comment/reply/%node',
// Callback to add items to the delegator task administration form:
'task admin' => 'delegator_comment_reply_task_admin',
// Menu hooks so that we can alter the comment/reply/%node menu entry to point to us.
'hook menu' => 'delegator_comment_reply_menu',
'hook menu alter' => 'delegator_comment_reply_menu_alter',
// This is task uses 'context' handlers and must implement these to give the
// handler data it needs.
'handler type' => 'context',
'get arguments' => 'delegator_comment_reply_get_arguments',
'get context placeholders' => 'delegator_comment_reply_get_contexts',
);
}
/**
* Callback defined by delegator_comment_reply_delegator_tasks().
*
* Alter the comment reply input so that comment reply comes to us rather than the
* normal comment reply process.
*/
function delegator_comment_reply_menu_alter(&$items, $task) {
// Override the comment reply handler for our purpose.
if ($items['comment/reply/%node']['page callback'] == 'comment_reply' || variable_get('delegator_override_anyway', FALSE)) {
$items['comment/reply/%node']['page callback'] = 'delegator_comment_reply';
$items['comment/reply/%node']['file path'] = $task['path'];
$items['comment/reply/%node']['file'] = $task['file'];
}
// @todo override node revision handler as well?
}
/**
* Warn if we are unable to override the taxonomy term page.
*/
function delegator_comment_reply_task_admin(&$form, &$form_state) {
$callback = db_result(db_query("SELECT page_callback FROM {menu_router} WHERE path = 'comment/reply/%'"));
if ($callback != 'delegator_comment_reply') {
drupal_set_message(t('Delegator module is unable to override comment/reply/%node node because some other module already has overridden with %callback. Delegator will not be able to handle this page.', array('%callback' => $callback)), 'warning');
}
}
/**
* Entry point for our overridden comment reply.
*
* This function asks its assigned handlers who, if anyone, would like
* to run with it. If no one does, it passes through to Drupal core's
* comment reply, which is comment_reply().
*/
function delegator_comment_reply($node) {
// Load my task plugin
$task = delegator_get_task('comment_reply');
// Load the node into a context.
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) {
node_tag_new($node->nid);
return $output;
}
// Otherwise, fall back.
return comment_reply($node);
}
/**
* Callback to get arguments provided by this task handler.
*
* Since this is the comment reply and there is no UI on the arguments, we
* create dummy arguments that contain the needed data.
*/
function delegator_comment_reply_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'node',
'identifier' => t('Node beeing replied'),
'id' => 1,
'name' => 'nid',
'settings' => array(),
),
);
}
/**
* Callback to get context placeholders provided by this handler.
*/
function delegator_comment_reply_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(delegator_comment_reply_get_arguments($task, $subtask_id));
}