You are here

function social_group_invite_block_access in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_block_access()
  2. 10.0.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_block_access()
  3. 10.1.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_block_access()
  4. 10.2.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_block_access()

Implements hook_block_access().

File

modules/social_features/social_group/modules/social_group_invite/social_group_invite.module, line 72
The Social Invite group module.

Code

function social_group_invite_block_access(Block $block, $operation, AccountInterface $account) {
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  $routes_to_check = [
    'entity.group_content.add_form',
    'entity.group_content.delete_form',
  ];

  // Only when on the confirm page of removing or adding invites
  // we remove the block for tasks and heros,the cancel button
  // will allow users to go back.
  if (in_array($route_name, $routes_to_check)) {
    $block_id = $block
      ->getPluginId();

    /** @var \Drupal\group\Entity\GroupContent $group_content */
    $group_content = \Drupal::routeMatch()
      ->getParameter('group_content');

    // Only if we are sure it's a group invitation.
    if (NULL !== $group_content && NULL !== $group_content
      ->getGroupContentType() && $group_content
      ->getGroupContentType()
      ->getContentPluginId() === 'group_invitation') {

      // This is a list of the blocks that this function cares about,
      // if we're being called for a different block we exit early.
      $hide_blocks = [
        'group_hero_block',
        'local_tasks_block',
      ];
      if (!in_array($block_id, $hide_blocks)) {
        return AccessResult::neutral();
      }

      // Remove the blocks.
      return AccessResult::forbidden();
    }
  }
}