You are here

public function GroupAddBlock::blockAccess in Open Social 8.9

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

Custom access logic to display the block.

Overrides BlockPluginTrait::blockAccess

File

modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php, line 99

Class

GroupAddBlock
Provides a 'GroupAddBlock' block.

Namespace

Drupal\social_group\Plugin\Block

Code

public function blockAccess(AccountInterface $account) {
  $route_user_id = $this->routeMatch
    ->getParameter('user');

  // Show this block only on current user Groups page.
  $can_create_groups = FALSE;
  foreach (GroupType::loadMultiple() as $group_type) {
    $permissions = 'create ' . $group_type
      ->id() . ' group';
    if ($account
      ->hasPermission($permissions)) {
      $can_create_groups = TRUE;
      break;
    }
  }
  if ($account
    ->id() == $route_user_id && $can_create_groups) {
    return AccessResult::allowed();
  }

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