public function GroupAddBlock::blockAccess in Open Social 10.2.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8.2 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8.3 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8.4 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8.5 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8.6 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8.7 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 8.8 modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 10.3.x modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 10.0.x modules/social_features/social_group/src/Plugin/Block/GroupAddBlock.php \Drupal\social_group\Plugin\Block\GroupAddBlock::blockAccess()
- 10.1.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\BlockCode
public function blockAccess(AccountInterface $account) {
if (!$this
->getUrl()
->access($account)) {
return AccessResult::forbidden();
}
$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();
}