You are here

function social_post_comment_create_access in Open Social 8

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

Implements hook_ENTITY_TYPE_create_access().

File

modules/social_features/social_post/social_post.module, line 203
The Social post module.

Code

function social_post_comment_create_access(AccountInterface $account, array $context, $entity_bundle) {
  if ($entity_bundle === 'post_comment') {
    $group = \Drupal::routeMatch()
      ->getParameter('group');
    if (is_numeric($group) && !$group instanceof GroupInterface) {
      $group = Group::load($group);
    }
    if ($group) {
      if ($group
        ->hasPermission('add post entities in group', $account)) {
        return AccessResult::allowed()
          ->cachePerUser();
      }
      else {
        return AccessResult::forbidden()
          ->cachePerUser();
      }
    }
  }
  return AccessResult::neutral();
}