2

I'm using threaded comments on my Drupal 7 site, and I'd like to be able to publicly preserve the fact that so-and-so commented here, and these were the replies. However, when a comment is deleted, all the replies are removed too. When a comment is deleted, I want the comment text to be changed to "DELETED" instead of actually deleting the comments.

I know about the un-publishing and hidden-comment kind of solutions, but I'd like the specific functionality I described instead of a workaround like those.

4
  • 1
    How about adding a new field on the comment type called "deleted" that only people with roles can see it. then when this deleted field is checked it would show "deleted" text on your comment?
    – saadlulu
    Sep 30 '12 at 12:42
  • +1 for the good idea, but the thing is, I want to modify the behavior of the default delete link. For example, to be able to use the delete link in comment moderation views, instead of making the moderator click extra times to open the edit page and select the field.
    – BenjaminRH
    Sep 30 '12 at 12:52
  • You can copy the comment.tpl.php from drupal basic theme and copy it inside your theme, then you would check the comment if it has your field checked. if its checked then print an html like <a href="/node/node-id/delete">Delete this comment</a>
    – saadlulu
    Sep 30 '12 at 13:21
  • Actually the code above deletes the whole node. use comment/comment-id/delete
    – saadlulu
    Sep 30 '12 at 13:26
0

I use module Comment Delete, rewritten for Drupal 7. Here is the code that is responsible for what you need:

$num_replies = db_query('SELECT COUNT(cid) FROM {comment} WHERE pid = :cid AND status = :status', array(':cid' => $comment->cid, ':status' => COMMENT_PUBLISHED))->fetchField();
if ($num_replies) {
  $comment->comment_body[LANGUAGE_NONE][0]['value'] = t('[The comment subject/body has been deleted, all replies will remain]');
  comment_save($comment);
  drupal_set_message(t('The comment subject/body has been deleted, all replies will remain.'));
}
else {
  comment_delete($comment->cid);
  drupal_set_message(t('The comment has been deleted.'));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.