function ajax_comments_delete in AJAX Comments 7
Callback for clicking "delete".
1 string reference to 'ajax_comments_delete'
- ajax_comments_menu in ./
ajax_comments.module - Implements hook_menu().
File
- ./
ajax_comments.module, line 707 - AJAX comments module file.
Code
function ajax_comments_delete($cid) {
if (!($comment = comment_load($cid))) {
return MENU_NOT_FOUND;
}
// Need to include comment module admin file for delete form.
$form_state = array();
$form_state['build_info']['args'] = array(
$comment,
);
// Load this using form_load_include so it's cached properly and works in the
// ajax callback.
form_load_include($form_state, 'inc', 'comment', 'comment.admin');
// Get child comments (replies on this comment)
$form_state['storage']['cids'] = array();
$query = db_select('comment', 'c');
$query
->addField('c', 'cid');
$query
->condition('c.nid', $comment->nid)
->condition('c.thread', substr($comment->thread, 0, -1) . '.%', 'LIKE')
->addTag('node_access');
if (!user_access('administer comments')) {
$query
->condition('c.status', COMMENT_PUBLISHED);
}
$query
->orderBy('c.cid', 'ASC');
$cids = $query
->execute()
->fetchCol();
// Save child comments ids if they are exist
if (!empty($cids)) {
$form_state['storage']['cids'] = $cids;
}
$form_build = drupal_build_form('comment_confirm_delete', $form_state);
$form = drupal_render($form_build);
// Hide contents.
$commands[] = ajax_command_invoke('.comment-wrapper-' . $cid . ' >*', 'hide');
// Put form inside main comment wrapper.
$commands[] = ajax_command_prepend('.comment-wrapper-' . $cid, $form);
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}