You are here

protected function PostGroupBlock::blockAccess in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  2. 8 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  3. 8.2 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  4. 8.4 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  5. 8.5 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  6. 8.6 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  7. 8.7 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  8. 8.8 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  9. 10.3.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  10. 10.0.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  11. 10.1.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()
  12. 10.2.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php \Drupal\social_post\Plugin\Block\PostGroupBlock::blockAccess()

Indicates whether the block should be shown.

Blocks with specific access checking should override this method rather than access(), in order to avoid repeating the handling of the $return_as_object argument.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user session for which to check access.

Return value

\Drupal\Core\Access\AccessResult The access result.

Overrides PostBlock::blockAccess

See also

self::access()

File

modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php, line 32

Class

PostGroupBlock
Provides a 'PostGroupBlock' block.

Namespace

Drupal\social_post\Plugin\Block

Code

protected function blockAccess(AccountInterface $account) {
  $group = _social_group_get_current_group();
  if (is_object($group)) {
    if ($group
      ->hasPermission('add post entities in group', $account) && $account
      ->hasPermission("add post entities")) {
      $membership = $group
        ->getMember($account);
      $context = [];
      if (!empty($membership)) {
        $group_content = $membership
          ->getGroupContent();
        $context = [
          'group_content' => $group_content,
        ];
      }
      return \Drupal::entityTypeManager()
        ->getAccessControlHandler($this->entityType)
        ->createAccess($this->bundle, $account, $context, TRUE);
    }
  }

  // By default, the block is not visible.
  return AccessResult::forbidden()
    ->setCacheMaxAge(0);
}