You are here

protected function RoleAccess::createTransientAccountWithRole in Search API 8

Creates a transient user with the given role for access checking.

No user entity will be created or saved.

Parameters

\Drupal\user\RoleInterface $role: The ID of the role for which to create a user session.

Return value

\Drupal\Core\Session\AccountInterface A representation of a user account with the given role.

1 call to RoleAccess::createTransientAccountWithRole()
RoleAccess::addFieldValues in src/Plugin/search_api/processor/RoleAccess.php
Adds the values of properties defined by this processor to the item.

File

src/Plugin/search_api/processor/RoleAccess.php, line 151

Class

RoleAccess
Adds access checks based on user roles.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

protected function createTransientAccountWithRole(RoleInterface $role) : AccountInterface {
  $role_id = $role
    ->id();
  if (empty(static::$roleDummyAccounts[$role_id])) {
    if ($role_id === AccountInterface::ANONYMOUS_ROLE) {
      $uid = 0;
    }
    else {
      $uid = --static::$lastUsedUid;
    }
    static::$roleDummyAccounts[$role_id] = new UserSession([
      'roles' => [
        $role_id,
      ],
      'uid' => $uid,
    ]);
  }
  return static::$roleDummyAccounts[$role_id];
}