You are here

protected function OgMembership::hasGroup in Organic groups 8

Checks if a group has already been populated on the membership.

The group is required for a membership, so it is always present if a membership has been saved. This is intended for internal use to verify if a group is present when methods are called on a membership that is possibly still under construction.

For performance reasons this avoids loading the full group entity just for this purpose, and relies only on the fact that the data for the entity is populated in the relevant fields. This should give us the same indication, but with a lower performance cost, especially for users that are a member of a large number of groups.

Return value

bool Whether or not the group is already present.

2 calls to OgMembership::hasGroup()
OgMembership::getRoles in src/Entity/OgMembership.php
Gets all the referenced OG roles.
OgMembership::getRolesIds in src/Entity/OgMembership.php
Gets all the referenced OG role IDs.

File

src/Entity/OgMembership.php, line 187

Class

OgMembership
The membership entity that connects a group and a user.

Namespace

Drupal\og\Entity

Code

protected function hasGroup() : bool {
  $has_group = !empty($this
    ->getFieldValue('entity_type', 'value')) && !empty($this
    ->getFieldValue('entity_bundle', 'value')) && !empty($this
    ->getFieldValue('entity_id', 'value'));
  return $has_group;
}