You are here

function comment_perm_form_alter in Comment Permissions 7.2

Same name and namespace in other branches
  1. 5 comment_perm.module \comment_perm_form_alter()
  2. 6 comment_perm.module \comment_perm_form_alter()
  3. 7 comment_perm.module \comment_perm_form_alter()

Implements hook_form_alter().

File

./comment_perm.module, line 170
Control commenting permissions by role and by node type.

Code

function comment_perm_form_alter(&$form, &$form_state, $form_id) {

  // Allow users to administer comment settings per node type.
  if (!empty($form['#node_edit_form']) && isset($form['comment_settings'])) {

    // Determine if user has access to administer comments.
    if (comment_perm_active_type($form['#node']->type) && comment_perm_administer_access($form['#node'])) {
      $form['comment_settings']['#access'] = TRUE;
    }
  }
  if (!isset($form['#id']) || $form['#id'] != 'comment-form') {
    return;
  }
  $node = $form['#node'];
  if (!comment_perm_active_type($node->type)) {
    return;
  }

  // Restrict access to comment reply form.
  if (!comment_perm_post_access($node) && !comment_perm_administer_access($node)) {
    if (arg(0) == 'comment' && (arg(1) == 'reply' || arg(2) == 'edit')) {
      drupal_access_denied();
    }
  }

  // Restrict access to comment edit form.
  if (!comment_perm_edit_access($node) && !comment_perm_administer_access($node)) {
    if (arg(0) == 'comment' && arg(2) == 'edit') {
      drupal_access_denied();
    }
  }
}