You are here

function social_comment_comment_access in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  2. 8 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  3. 8.2 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  4. 8.3 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  5. 8.4 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  6. 8.5 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  7. 8.6 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  8. 8.7 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  9. 8.8 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  10. 10.0.x modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  11. 10.1.x modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  12. 10.2.x modules/social_features/social_comment/social_comment.module \social_comment_comment_access()

Implements hook_ENTITY_TYPE_access().

Allow users to delete their own comments.

File

modules/social_features/social_comment/social_comment.module, line 268
The Social comment module.

Code

function social_comment_comment_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation === 'delete') {
    if ($account
      ->hasPermission('administer comments')) {
      return AccessResult::allowed()
        ->cachePerPermissions();
    }
    else {

      /** @var \Drupal\comment\CommentInterface $entity */
      return AccessResult::allowedIfHasPermission($account, 'delete own comments')
        ->andIf(AccessResult::allowedIf($account
        ->id() == $entity
        ->getOwnerId()))
        ->cachePerPermissions()
        ->cachePerUser()
        ->addCacheableDependency($entity);
    }
  }
  return AccessResult::neutral();
}