1

I'm looking for a way to allow a non-admin user to approve comments. I thought a Flag/Rules combination might be a solution but I can't figure it out.

I added a content-moderator role, then I created a view listing comments awaiting moderation. After that, I set up a flag to approve comments and added the flag link within the view, bu there is no Rules action that approves comments once the flag is clicked.

Do you have any idea?

2

You need to give the "Administer comments and comment settings" permission to the role and then it will be able to approve the comment.

0

You also can write a tiny module and add this Rule Action, to do that you will need a .info file, an empty .module file and a .rules.inc file, in this file you will need to implement hook_rules_action_info to tell drupal about your custom Action and at last you will need a function to do the job for you.

here is a simple code which will do the job for you:

/**
 * @file MODULE_NAME.rules.inc
 * Contains custom code for Rules module.
 */
/**
 * Implements hook_rules_action_info().
 */
function MODULE_NAME_rules_action_info() {
  return array(
    'MODULE_NAME_action_approve_comment' => array(
      'label' => t('Approve Comment'),
      'group' => t('Comment'),
      'parameter' => array(
        'account' => array(
          'type' => 'integer',//cid of comment will be passed to function
          'label' => t('Comment ID'),
        ),
      ),
    ),
  );
}
/**
 * Rule action comment approve.
 */
function MODULE_NAME_action_approve_comment($cid) {
  $comment->status = COMMENT_PUBLISHED;
  db_update('comment')
    ->fields(array(
      'status' => $comment->status,
    ))
    ->condition('cid', $cid)
    ->execute();
}

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.