You are here

function social_comment_comment_access in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  2. 8.2 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  3. 8.3 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  4. 8.4 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  5. 8.5 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  6. 8.6 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  7. 8.7 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  8. 8.8 modules/social_features/social_comment/social_comment.module \social_comment_comment_access()
  9. 10.3.x 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 164
The Social comment module.

Code

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