function social_group_can_view_groups_of_type in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/social_group.module \social_group_can_view_groups_of_type()
- 8.7 modules/social_features/social_group/social_group.module \social_group_can_view_groups_of_type()
- 8.8 modules/social_features/social_group/social_group.module \social_group_can_view_groups_of_type()
- 10.3.x modules/social_features/social_group/social_group.module \social_group_can_view_groups_of_type()
- 10.0.x modules/social_features/social_group/social_group.module \social_group_can_view_groups_of_type()
- 10.1.x modules/social_features/social_group/social_group.module \social_group_can_view_groups_of_type()
- 10.2.x modules/social_features/social_group/social_group.module \social_group_can_view_groups_of_type()
Determine whether a user can see groups of a given type as an outsider.
Parameters
string $type: The group type to check.
\Drupal\Core\Session\AccountInterface $account: The user to check for.
Return value
bool Whether the user is allowed to view groups of the given type.
1 call to social_group_can_view_groups_of_type()
- social_group_secret_can_view_secret_groups in modules/
social_features/ social_group/ modules/ social_group_secret/ social_group_secret.module - Determine whether a user can see secret groups as outsider.
File
- modules/
social_features/ social_group/ social_group.module, line 1830 - The Social group module.
Code
function social_group_can_view_groups_of_type(string $type, AccountInterface $account) : bool {
$group_type = GroupType::load($type);
// If the group type doesn't exist then the user can't see the group type.
if ($group_type === FALSE) {
return FALSE;
}
// Anonymous users have a special role.
if ($account
->isAnonymous()) {
/** @var \Drupal\group\Entity\GroupRoleInterface $role */
return $group_type
->getAnonymousRole()
->hasPermission('view group');
}
// The service that keeps platform roles in sync with group roles for
// outsiders.
/** @var \Drupal\group\GroupRoleSynchronizerInterface $group_role_synchroniser */
$group_role_synchroniser = \Drupal::service('group_role.synchronizer');
/** @var \Drupal\group\Entity\GroupRoleInterface[] $group_roles */
$group_roles = $group_type
->getRoles();
$user_roles = $account
->getRoles(TRUE);
// Check each role this user has whether its group counterpart has the correct
// permission.
foreach ($user_roles as $role) {
$group_role = $group_role_synchroniser
->getGroupRoleId($type, $role);
if ($group_roles[$group_role]
->hasPermission('view group')) {
return TRUE;
}
}
// The user has no role that can view the group type.
return FALSE;
}