You are here

function authcache_comment_comment_view_alter in Authenticated User Page Caching (Authcache) 7.2

Implements hook_comment_view_alter().

Replace the edit-link on comments if all of the following conditions are met:

1. Comment is published 2. A user has the right to edit its own comments 3. 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

comment_links()

comment_access()

File

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

Code

function authcache_comment_comment_view_alter(&$build) {
  global $user;
  if ($user->uid && authcache_page_is_cacheable()) {
    $comment = $build['#comment'];
    if ($comment->status == COMMENT_PUBLISHED && user_access('edit own comments') && !user_access('administer comments')) {

      // Ensure that comment-edit link will always show up in the same place.
      unset($build['links']['comment']['#links']['comment-edit']);
      $build['links']['comment']['#links']['comment-edit'] = array(
        'title' => t('edit'),
        'href' => "comment/{$comment->cid}/edit",
        'attributes' => array(
          'class' => array(
            'authcache-comment-edit',
            'element-hidden',
          ),
          'data-p13n-uid' => $comment->uid,
        ),
        'html' => TRUE,
      );
      $build['#attached']['js'][] = drupal_get_path('module', 'authcache_comment') . '/authcache_comment.js';

      // Ensure that the authcacheUser setting is added to the page, such that
      // authcache_comment.js can work with that data.
      authcache_p13n_attach($build, array(
        '#setting' => 'user',
      ));
    }
  }
}