You are here

function authcache_comment_node_view_alter in Authenticated User Page Caching (Authcache) 7.2

Implements hook_comment_view_alter().

Hide the number-of-new-comments-link on node teasers.

File

modules/authcache_comment/authcache_comment.module, line 31
Provide personalization for the comment module.

Code

function authcache_comment_node_view_alter(&$build) {
  global $user;
  if ($user->uid && authcache_page_is_cacheable()) {
    $node = $build['#node'];

    // Note that we check here whether comment-comments is in the links. We do
    // not need to show new-comments link when no comments have been posted in
    // the first place. Also note that we cannot test for comment-new-comments
    // because existance of this link depends on the logged in user.
    if (isset($build['links']['comment']['#links']['comment-comments'])) {

      // Replace the number-of-new-comments link with placeholder markup. Note
      // that the title cannot be empty, otherwise no markup will be generated.
      $build['links']['comment']['#links']['comment-new-comments']['title'] = ' ';
      $build['links']['comment']['#links']['comment-new-comments']['attributes']['data-p13n-nid'] = $node->nid;
      $build['links']['comment']['#links']['comment-new-comments']['attributes']['class'][] = 'authcache-comment-num-new';
      unset($build['links']['comment']['#links']['comment-new-comments']['href']);
      unset($build['links']['comment']['#links']['comment-new-comments']['query']);
      unset($build['links']['comment']['#links']['comment-new-comments']['fragment']);
      authcache_p13n_add_setting(array(
        '#setting' => 'comment-num-new',
        '#param' => array(
          'cn' => array(
            $node->nid,
          ),
        ),
      ));
      $build['#attached']['js'][] = drupal_get_path('module', 'authcache_comment') . '/authcache_comment.js';
    }
  }
}