protected function EnrollActionBlock::blockAccess in Open Social 8.7
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 8 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 8.2 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 8.3 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 8.4 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 8.5 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 8.6 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 8.8 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 10.3.x modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 10.0.x modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 10.1.x modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
- 10.2.x modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
Custom access logic to display the block on the hero region for an event.
Overrides BlockPluginTrait::blockAccess
File
- modules/
social_features/ social_event/ src/ Plugin/ Block/ EnrollActionBlock.php, line 76
Class
- EnrollActionBlock
- Provides a 'EnrollActionBlock' block.
Namespace
Drupal\social_event\Plugin\BlockCode
protected function blockAccess(AccountInterface $account) {
$route_name = $this->routeMatch
->getRouteName();
$routes_to_check = [
'view.event_enrollments.view_enrollments',
'entity.node.canonical',
'view.managers.view_managers',
];
if (in_array($route_name, $routes_to_check)) {
$node = $this->routeMatch
->getParameter('node');
if (!is_null($node) && !is_object($node)) {
$node = node_load($node);
}
if (is_object($node) && $node
->getType() === 'event') {
// Retrieve the group and if there are groups respect group permission.
$groups = $this
->getGroups($node);
if (!empty($groups)) {
foreach ($groups as $group) {
if ($group
->hasPermission('enroll to events in groups', $account)) {
return AccessResult::allowed();
}
}
}
else {
// @TODO Always show the block when the user is already enrolled.
return AccessResult::allowed();
}
}
}
// By default, the block is not visible.
return AccessResult::forbidden();
}