You are here

protected function EnrollActionBlock::blockAccess in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  2. 8 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  3. 8.2 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  4. 8.3 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  5. 8.4 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  6. 8.5 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  7. 8.6 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  8. 8.8 modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  9. 10.3.x modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  10. 10.0.x modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  11. 10.1.x modules/social_features/social_event/src/Plugin/Block/EnrollActionBlock.php \Drupal\social_event\Plugin\Block\EnrollActionBlock::blockAccess()
  12. 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\Block

Code

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();
}