You are here

public function GroupMembershipLoader::load in Group 8

Same name and namespace in other branches
  1. 2.0.x src/GroupMembershipLoader.php \Drupal\group\GroupMembershipLoader::load()

Loads a membership by group and user.

Parameters

\Drupal\group\Entity\GroupInterface $group: The group to load the membership from.

\Drupal\Core\Session\AccountInterface $account: The user to load the membership for.

Return value

\Drupal\group\GroupMembership|false The loaded GroupMembership or FALSE if none was found.

Overrides GroupMembershipLoaderInterface::load

File

src/GroupMembershipLoader.php, line 80

Class

GroupMembershipLoader
Loader for wrapped GroupContent entities using the 'group_membership' plugin.

Namespace

Drupal\group

Code

public function load(GroupInterface $group, AccountInterface $account) {
  $filters = [
    'entity_id' => $account
      ->id(),
  ];
  $group_contents = $this
    ->groupContentStorage()
    ->loadByGroup($group, 'group_membership', $filters);
  $group_memberships = $this
    ->wrapGroupContentEntities($group_contents);
  return $group_memberships ? reset($group_memberships) : FALSE;
}