public function FlexibleGroupContentAccessCheck::access in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/modules/social_group_flexible_group/src/Access/FlexibleGroupContentAccessCheck.php \Drupal\social_group_flexible_group\Access\FlexibleGroupContentAccessCheck::access()
- 8.7 modules/social_features/social_group/modules/social_group_flexible_group/src/Access/FlexibleGroupContentAccessCheck.php \Drupal\social_group_flexible_group\Access\FlexibleGroupContentAccessCheck::access()
- 8.8 modules/social_features/social_group/modules/social_group_flexible_group/src/Access/FlexibleGroupContentAccessCheck.php \Drupal\social_group_flexible_group\Access\FlexibleGroupContentAccessCheck::access()
- 10.3.x modules/social_features/social_group/modules/social_group_flexible_group/src/Access/FlexibleGroupContentAccessCheck.php \Drupal\social_group_flexible_group\Access\FlexibleGroupContentAccessCheck::access()
- 10.0.x modules/social_features/social_group/modules/social_group_flexible_group/src/Access/FlexibleGroupContentAccessCheck.php \Drupal\social_group_flexible_group\Access\FlexibleGroupContentAccessCheck::access()
- 10.1.x modules/social_features/social_group/modules/social_group_flexible_group/src/Access/FlexibleGroupContentAccessCheck.php \Drupal\social_group_flexible_group\Access\FlexibleGroupContentAccessCheck::access()
- 10.2.x modules/social_features/social_group/modules/social_group_flexible_group/src/Access/FlexibleGroupContentAccessCheck.php \Drupal\social_group_flexible_group\Access\FlexibleGroupContentAccessCheck::access()
Checks access.
Parameters
\Symfony\Component\Routing\Route $route: The route to check against.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route.
\Drupal\Core\Session\AccountInterface $account: The account to check access for.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- modules/
social_features/ social_group/ modules/ social_group_flexible_group/ src/ Access/ FlexibleGroupContentAccessCheck.php, line 31
Class
- FlexibleGroupContentAccessCheck
- Determines access to routes based flexible_group membership and settings.
Namespace
Drupal\social_group_flexible_group\AccessCode
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
$permission = $route
->getRequirement('_flexible_group_content_visibility');
$group_permission = $route
->getRequirement('_group_permission');
// Don't interfere if no permission was specified.
if ($permission === NULL) {
return AccessResult::allowed();
}
// Don't interfere if no group was specified.
$parameters = $route_match
->getParameters();
if (!$parameters
->has('group')) {
return AccessResult::allowed();
}
// Don't interfere if the group isn't a real group.
$group = $parameters
->get('group');
if (!$group instanceof GroupInterface) {
return AccessResult::allowed();
}
$type = $group
->getGroupType();
// Don't interfere if the group isn't a flexible group.
if ($type instanceof GroupTypeInterface && $type
->id() !== 'flexible_group') {
return AccessResult::allowed();
}
// A user with this access can definitely do everything.
if ($account
->hasPermission('manage all groups')) {
return AccessResult::allowed();
}
// AN Users aren't allowed anything if Public isn't an option.
if (!$account
->isAuthenticated() && !social_group_flexible_group_public_enabled($group)) {
return AccessResult::forbidden();
}
// If User is a member we can also rely on Group to take permissions.
if ($group
->getMember($account) !== FALSE) {
return AccessResult::allowed()
->addCacheableDependency($group);
}
// It's a non member but Community isn't enabled.
// No access for you only for the about page.
if ($account
->isAuthenticated() && !social_group_flexible_group_community_enabled($group) && $route_match
->getRouteName() !== 'view.group_information.page_group_about' && $route_match
->getRouteName() !== 'entity.group.canonical' && $route_match
->getRouteName() !== 'view.group_members.page_group_members') {
return AccessResult::forbidden()
->addCacheableDependency($group);
}
// We allow it but lets add the group as dependency to the cache
// now because field value might be edited and cache should
// clear accordingly.
return AccessResult::allowed()
->addCacheableDependency($group);
}