You are here

function ajax_comments_comment_view_alter in AJAX Comments 7

Implements hook_comment_view_alter().

File

./ajax_comments.module, line 489
AJAX comments module file.

Code

function ajax_comments_comment_view_alter(&$build) {
  global $user;

  // Check
  if (ajax_comments_node_type_active($build['#node']->type)) {

    // A little HACK for do not mark as NEW own comments
    if (isset($build['#comment']->new) && $build['#comment']->uid == $user->uid && ($build['#comment']->new == MARK_NEW || $build['#comment']->new == MARK_UPDATED)) {
      $build['#comment']->new = MARK_READ;
    }

    // Reply.
    if (isset($build['links']['comment']['#links']['comment-reply'])) {
      $classes = array(
        'use-ajax-comments',
        'ajax-comments-reply',
        'ajax-comments-reply-' . $build['#comment']->nid . '-' . $build['#comment']->cid,
      );
      if (empty($build['links']['comment']['#links']['comment-reply']['attributes']['class'])) {
        $build['links']['comment']['#links']['comment-reply']['attributes']['class'] = $classes;
      }
      else {
        $build['links']['comment']['#links']['comment-reply']['attributes']['class'] = array_unique(array_merge($build['links']['comment']['#links']['comment-reply']['attributes']['class'], $classes));
      }
    }

    // Edit.
    if (isset($build['links']['comment']['#links']['comment-edit'])) {
      $classes = array(
        'use-ajax-comments',
        'ajax-comments-edit',
        'ajax-comments-edit-' . $build['#comment']->cid,
      );
      if (empty($build['links']['comment']['#links']['comment-edit']['attributes']['class'])) {
        $build['links']['comment']['#links']['comment-edit']['attributes']['class'] = $classes;
      }
      else {
        $build['links']['comment']['#links']['comment-edit']['attributes']['class'] = array_unique(array_merge($build['links']['comment']['#links']['comment-edit']['attributes']['class'], $classes));
      }
    }

    // Delete.
    if (isset($build['links']['comment']['#links']['comment-delete'])) {
      $classes = array(
        'use-ajax-comments',
        'ajax-comments-delete',
        'ajax-comments-delete-' . $build['#comment']->cid,
      );
      if (empty($build['links']['comment']['#links']['comment-delete']['attributes']['class'])) {
        $build['links']['comment']['#links']['comment-delete']['attributes']['class'] = $classes;
      }
      else {
        $build['links']['comment']['#links']['comment-delete']['attributes']['class'] = array_unique(array_merge($build['links']['comment']['#links']['comment-delete']['attributes']['class'], $classes));
      }
    }
  }
}