function social_group_invite_block_access in Open Social 10.1.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_block_access()
- 10.3.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_block_access()
- 10.0.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_block_access()
- 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 73 - 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();
}
}
}