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? Commented Sep 30, 2012 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. Commented Sep 30, 2012 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> Commented Sep 30, 2012 at 13:21
  • Actually the code above deletes the whole node. use comment/comment-id/delete Commented Sep 30, 2012 at 13:26

1 Answer 1

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.')); } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.