1) User X (with a defined role) posts a comment to a content type like forum or blog.
2) An 'edit' link is now visible to user X for that comment.
3) User Y (regardless of its role) posts a new comment in reply to user X's comment.
4) The 'edit' link is no longer visible to user X.
5) If user Y's comment is deleted, user X can once again see the 'edit' link.

The expected behavior is for the comment to be editable by its owner independently of any threading to that comment.
Instead, the comment is editable by its owner only if no one replied to it.

Note:
- This behavior is consistent, across user roles, content types, and custom/garland themes.
- For an 'admin' user role (the only one with 'administer comments' permission) the 'edit' link does appear as expected.

Comments

SpikeX’s picture

Subscribed. I think this is stupid behavior that needs to be fixed, or at least optionalized.

SpikeX’s picture

If you want this behavior off, for now, you can hack your core file to remove it. I don't recommend this, but if you're desperate:

Find this code in /modules/comment/comment.module

function comment_access($op, $comment) {
  global $user;

  if ($op == 'edit') {
    return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || user_access('administer comments');
  }
}

And replace it with this:

function comment_access($op, $comment) {
  global $user;

  if ($op == 'edit') {
    return ($user->uid && $user->uid == $comment->uid) || user_access('administer comments');
  }
}
dsanchez’s picture

I think an user should be able to edit his comment at any time. A message, however, could be shown at the bottom of the comment, something like "Comment edited by xxxx on the date"

jose reyero’s picture

Status: Active » Closed (won't fix)

I think this (the current one) is just the expected behavior for comments and if comments could be edited after a reply most of us would need an option to disable that.

Thus, this is not a bug, but a design decision and changing that would make a feature request for either Drupal 7 or Drupal 8.

See #10700: Ability to delete own comments before reply is added

j.c.gram’s picture

For anyone looking to do this without hacking core:


function mymodule_link_alter(&$links, $node, $comment = NULL) {
  if ($comment) {
    if (mymodule_comment_access('edit', $comment)) {
      $links['comment_edit'] = array(
        'title' => t('edit'),
        'href' => "comment/edit/$comment->cid"
      );
    }
  }
}


function mymodule_comment_access($op, $comment) {
  global $user;

  if ($op == 'edit') {
    return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) >= 1 && $comment->status == COMMENT_PUBLISHED) || user_access('administer comments');
  }
}


function mymodule_comment_edit($cid) {
  global $user;

  $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid));
  $comment = drupal_unpack($comment);
  $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
  if (comment_access('edit', $comment) || mymodule_comment_access('edit', $comment)) {
    return comment_form_box((array)$comment);
  }
  else {
    drupal_access_denied();
  }
} 


function mymodule_menu_alter(&$items) {
  $items['comment/edit']['page callback'] = 'mymodule_comment_edit';
}

sgtsaughter’s picture

Tested #7 and it works when I put it in my custom module. You just have to put an open quote in the last line

mymodule_comment_edit';

change to

'mymodule_comment_edit';