2

I'm using the default Drupal 7 comments for my website and I would like to give specific roles the ability to edit any comment. My role can edit just about everything about a comment(Name, email, time etc.) but not the comment itself.

Only as user 1 I can edit the comments it seems.

Am I missing something here?

EDIT I just figured out that it's not the permission for the field. It's the permission for the Rich Text Editor that was wrong. Checking the normal Administer comments and settings was enough. I'm an idiot.

2 Answers 2

1

The permission drupal gives by default says 'edit own comments'. I do not see a permission which allows 'edit any comment'. Try using User Tweaks module. Module page says

edit any comments (and edit any comments), which allows user with the Post comments permission to edit comments. The permission is not required for users with the Administer comments permission.

Updated Answer-

I just saw the comment module code. You simply have to give Administer Comment Permission for that Role, but it will give delete permission as well.

If you are comfortable in custom coding you can alter the access callback for comment edit menu item.

If you see hook_menu implemented by comment module, here is the delete menu item code

 // Every other comment path uses %, but this one loads the comment directly,
  // so we don't end up loading it twice (in the page and access callback).
  $items ['comment/%comment/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'comment_edit_page',
    'page arguments' => array(1),
    'access callback' => 'comment_access',
    'access arguments' => array('edit', 1),
    'type' => MENU_LOCAL_TASK,
    'weight' => 0,
  );

which basically calls comment_access function as

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

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

You can implement hook_menu_alter to change access callback for edit, something as below.

  // Implements hook_menu_alter
  function mymodule_name_menu_alter(&$items)  {
    $items ['comment/%comment/edit']['access callback'] = '_my_module_name_custom_callbck';
  }

// Access Callbck for comment edit.

  function _my_module_name_custom_callbck($op, $comment) {
     if ($op == 'edit') {
     global $user;
      return (in_array('your_user_role', $user->roles) || $user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments');
    }
  }

Note: I have not evaluated why drupal is not giving it by default, it will still be important to identify.

7
  • Not a big fan of Alpha modules(Or modules either way). If I'd use a module I'd go for drupal.org/project/comment_perm I think. I'm still hoping for a non-module answer, though :-p Sep 16, 2015 at 9:21
  • makes sense, I just updated my answer, it might help
    – arpitr
    Sep 16, 2015 at 9:40
  • I've actually tried user_tweaks and user_tweaks_ui. It's a piece of garbage, tbh. A LOT of errors in it. I'll try custom coding it. However; your answer is about deleting. I'd like to EDIT any comment for a specific role. Sep 16, 2015 at 9:42
  • aah! I am updating again
    – arpitr
    Sep 16, 2015 at 9:46
  • Oh my; I just figured out that it's not the permission for the field. It's the permission for the Rich Text Editor that was wrong. Checking the normal Administer comments and settings was enough. I'm an idiot. Sep 16, 2015 at 10:02
0

Comment Permissions

The Comment Permissions module enables control of commenting by user role and by node type. Additional user permissions for selected node types are added to the user access system so you can configure commenting with more control than Drupal core provides.

ACL

The ACL module, short for Access Control Lists, is an API for other modules to create lists of users and give them access to nodes. It has no UI of its own and will not do anything by itself; install this module only if some other module tells you to.

3
  • I've installed Comment Permissions now. It gives me Four permissions to change. comment on any route content, comment without approval on any route content, comment without approval on own route content, edit own comments on route content. But not "Edit any comment on route content" Sep 16, 2015 at 9:27
  • go to admin>>people>>permission and check check-box again you role on administer comments and comments settings
    – Adi
    Sep 16, 2015 at 9:42
  • Oh my; I just figured out that it's not the permission for the field. It's the permission for the Rich Text Editor that was wrong. Checking the normal Administer comments and settings was enough. I'm an idiot. Sep 16, 2015 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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