You are here

function authcache_comment_view_alter in Authenticated User Page Caching (Authcache) 7

Implements hook_comment_view_alter().

File

./authcache.module, line 426
Authenticated User Page Caching (and anonymous users, too!)

Code

function authcache_comment_view_alter(&$build) {
  global $user, $_authcache_is_cacheable;

  // We only add/replace the authcache alterable edit link if:
  // 1. There is a logged in user
  // 2. The page can be cached
  // 3. Comment is published
  // 4. A user has the right to edit its own comments
  // 5. The user does *not* have administer comments permission
  //
  // If the logged in user belongs to a role with admin-permission, there is no
  // need to alter the link. If on the other hand, the user belongs to a role
  // without 'edit own comments' permission, the link will not be added by
  // comment_links anyway.
  // see also (in comment.module):
  // - comment_links
  // - comment_access
  $comment = $build['#comment'];
  if ($user->uid && $_authcache_is_cacheable && $comment->status == COMMENT_PUBLISHED && user_access('edit own comments') && !user_access('administer comments')) {
    $build['links']['comment']['#links']['comment-edit'] = array(
      'title' => t('edit'),
      'attributes' => array(
        'class' => array(
          'authcache-comment-edit',
        ),
        'data-comment-uid' => $comment->uid,
        'data-comment-href' => "comment/{$comment->cid}/edit",
      ),
      'html' => TRUE,
    );
  }
}