You are here

function comment_perm_node_view_alter in Comment Permissions 7.2

Same name and namespace in other branches
  1. 7 comment_perm.module \comment_perm_node_view_alter()

Implements hook_node_view_alter().

File

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

Code

function comment_perm_node_view_alter(&$build) {
  $node = $build['#node'];
  if (!comment_perm_active_type($node->type)) {
    return;
  }
  if (!comment_perm_access($node) && !comment_perm_administer_access($node)) {
    unset($build['comments']);
    return;
  }
  if (!comment_perm_post_access($node) && !comment_perm_administer_access($node)) {
    unset($build['comments']['comment_form'], $build['links']['comment']['#links']['comment-add']);
    if (variable_get('comment_perm_hide_comments', 0)) {
      unset($build['comments'], $build['links']['comment']);
      return;
    }
  }

  // Remove not approved comments from display.
  if (isset($build['comments']['comments']) && !comment_perm_administer_access($node)) {
    foreach ($build['comments']['comments'] as $key => $comment) {
      if (isset($comment['#comment']) && is_object($comment['#comment']) && $comment['#comment']->status == COMMENT_NOT_PUBLISHED) {
        unset($build['comments']['comments'][$key]);
      }
    }
  }
}