View source
<?php
function page_manager_comment_reply_page_manager_tasks() {
if (!module_exists('comment')) {
return;
}
return array(
'task type' => 'page',
'title' => t('Comment Reply page'),
'admin title' => t('Comment Reply page'),
'admin description' => t('When enabled, this overrides the default Drupal behavior for the site contact page at <em>/contact</em>. If no variant is selected, the default Drupal contact form will be used.'),
'admin path' => 'comment/reply/%node',
'hook menu alter' => 'page_manager_comment_reply_menu_alter',
'handler type' => 'context',
'get arguments' => 'page_manager_comment_reply_get_arguments',
'get context placeholders' => 'page_manager_comment_reply_get_contexts',
'disabled' => variable_get('page_manager_comment_reply_disabled', TRUE),
'enable callback' => 'page_manager_comment_reply_enable',
'access callback' => 'page_manager_comment_reply_check',
);
}
function page_manager_comment_reply_enable($cache, $status) {
variable_set('page_manager_comment_reply_disabled', $status);
if (!$status) {
$GLOBALS['page_manager_enabling_comment_reply'] = TRUE;
}
}
function page_manager_comment_reply_page($node, $pid = NULL) {
$task = page_manager_get_task('comment_reply');
ctools_include('context');
ctools_include('context-task-handler');
$contexts = ctools_context_handler_get_task_contexts($task, '', array(
$node,
$pid,
));
if (array_key_exists('argument_cid_3', $contexts) && $contexts['argument_cid_3']->data->nid != $node->nid) {
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
drupal_goto("node/{$node->nid}");
}
$output = ctools_context_handler_render($task, '', $contexts, array(
$node,
$pid,
));
if ($output !== FALSE) {
return $output;
}
$function = 'comment_reply';
foreach (module_implements('page_manager_override') as $module) {
$call = $module . '_page_manager_override';
if (($rc = $call('comment_reply')) && function_exists($rc)) {
$function = $rc;
break;
}
}
module_load_include('inc', 'comment', 'comment.pages');
return $function($node, $pid);
}
function page_manager_comment_reply_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'node',
'identifier' => t('Node being commented on'),
'id' => 2,
'name' => 'entity_id:node',
'settings' => array(),
),
array(
'keyword' => 'comment',
'identifier' => t('Comment being replied to'),
'id' => 3,
'name' => 'entity_id:comment',
'settings' => array(),
),
);
}
function page_manager_comment_reply_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(page_manager_comment_reply_get_arguments($task, $subtask_id));
}
function page_manager_comment_reply_menu_alter(&$items, $task) {
if (variable_get('page_manager_comment_reply_disabled', TRUE)) {
return;
}
$callback = $items['comment/reply/%node']['page callback'];
if ($callback == 'comment_reply' || variable_get('page_manager_override_anyway', FALSE)) {
$items['comment/reply/%node']['page callback'] = 'page_manager_comment_reply_page';
$items['comment/reply/%node']['file path'] = $task['path'];
$items['comment/reply/%node']['file'] = $task['file'];
}
else {
variable_set('page_manager_comment_reply_disabled', TRUE);
if (!empty($GLOBALS['page_manager_enabling_comment_reply'])) {
drupal_set_message(t('Page manager module is unable to enable comment/reply/%node because some other module already has overridden with %callback.', array(
'%callback' => $callback,
)), 'error');
}
}
}
function page_manager_comment_reply_access_check($task, $subtask_id, $contexts) {
$context = reset($contexts);
return TRUE;
}