public function OgMembership::isRoleValid in Organic groups 8
Returns whether the given role is valid for this membership.
Parameters
\Drupal\og\OgRoleInterface $role: The role to check.
Return value
bool True if the role is valid, false otherwise.
Throws
\LogicException Thrown when the validity of the role cannot be established, for example because the group hasn't yet been set on the membership.
Overrides OgMembershipInterface::isRoleValid
1 call to OgMembership::isRoleValid()
- OgMembership::preSave in src/
Entity/ OgMembership.php - Acts on an entity before the presave hook is invoked.
File
- src/
Entity/ OgMembership.php, line 323
Class
- OgMembership
- The membership entity that connects a group and a user.
Namespace
Drupal\og\EntityCode
public function isRoleValid(OgRoleInterface $role) : bool {
$group = $this
->getGroup();
// If there is no group yet then we cannot determine whether the role is
// valid.
if (!$group) {
throw new \LogicException('Cannot determine whether a role is valid for a membership that doesn\'t have a group.');
}
// Non-member roles are never valid for any membership.
if ($role
->getName() == OgRoleInterface::ANONYMOUS) {
return FALSE;
}
elseif ($role
->getGroupType() !== $group
->getEntityTypeId() || $role
->getGroupBundle() !== $group
->bundle()) {
return FALSE;
}
return TRUE;
}