You are here

function comment_og_comment_view_alter in Comment OG 7

Implements hook_comment_view_alter().

File

./comment_og.module, line 99
Provides comment integration for Organic Groups.

Code

function comment_og_comment_view_alter(&$build) {
  $links = array();
  $node = $build['#node'];
  $group = og_context();
  $comment = $build['#comment'];

  // Build the links array in group context (largely lifted from comment_link).
  if (isset($group->gid) && $node->comment == COMMENT_NODE_OPEN) {
    if (comment_og_access('delete', $comment, $group->gid)) {
      $links['comment-delete'] = array(
        'title' => t('delete'),
        'href' => "comment/{$comment->cid}/delete/{$group->gid}",
        'html' => TRUE,
      );
    }
    if (comment_og_access('edit', $comment, $group->gid)) {
      $links['comment-edit'] = array(
        'title' => t('edit'),
        'href' => "comment/{$comment->cid}/edit/{$group->gid}",
        'html' => TRUE,
      );
    }
    if (comment_og_access('post', $comment, $group->gid)) {
      $links['comment-reply'] = array(
        'title' => t('reply'),
        'href' => "comment/reply/{$comment->nid}/{$comment->cid}/{$group->gid}",
        'html' => TRUE,
      );
    }
    if (comment_og_access('approve', $comment, $group->gid)) {
      if ($comment->status == COMMENT_NOT_PUBLISHED) {
        $links['comment-approve'] = array(
          'title' => t('approve'),
          'href' => "comment/{$comment->cid}/approve/{$group->gid}",
          'html' => TRUE,
          'query' => array(
            'token' => drupal_get_token("comment/{$comment->cid}/approve/{$group->gid}"),
          ),
        );
      }
    }
    if (empty($links['comment-delete']) && empty($links['comment-edit']) && empty($links['comment-reply']) && empty($links['comment-approve'])) {
      $links['comment_forbidden']['title'] = theme('comment_post_forbidden', array(
        'node' => $node,
      ));
      $links['comment_forbidden']['html'] = TRUE;
    }
    $build['links']['comment']['#links'] = $links;
  }
}