You are here

public function OgMembership::getRolesIds in Organic groups 8

Gets all the referenced OG role IDs.

Return value

string[] List of OG role IDs that are granted in the membership.

Overrides OgMembershipInterface::getRolesIds

1 call to OgMembership::getRolesIds()
OgMembership::hasRole in src/Entity/OgMembership.php
Checks if the membership has the role with the given ID.

File

src/Entity/OgMembership.php, line 298

Class

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

Namespace

Drupal\og\Entity

Code

public function getRolesIds() : array {

  // Only use $this->get() if it is already populated. If it is not available
  // then use the raw value. This field is not translatable so we do not need
  // the slow field definition lookup from $this->getTranslatedField().
  if (isset($this->fields['roles'][LanguageInterface::LANGCODE_DEFAULT])) {
    $values = $this
      ->get('roles')
      ->getValue();
  }
  else {
    $values = $this->values['roles'][LanguageInterface::LANGCODE_DEFAULT] ?? [];
  }
  $roles_ids = array_column($values, 'target_id');

  // Add the member role. This is only possible if a group has been set on the
  // membership.
  if ($this
    ->hasGroup()) {
    $roles_ids[] = "{$this->getGroupEntityType()}-{$this->getGroupBundle()}-" . OgRoleInterface::AUTHENTICATED;
  }
  return $roles_ids;
}