public function TokenManager::getTokensForUser in Persistent Login 8
Get all active tokens for a user.
Parameters
\Drupal\user\UserInterface $user: A user to get active tokens for.
Return value
PersistentToken[] An array of the active tokens for the provided user.
File
- src/
TokenManager.php, line 261
Class
- TokenManager
- Class TokenManager.
Namespace
Drupal\persistent_loginCode
public function getTokensForUser(UserInterface $user) {
$tokens = [];
try {
$tokensResult = $this->connection
->select('persistent_login', 'pl')
->fields('pl', [
'uid',
'series',
'instance',
'created',
'refreshed',
'expires',
])
->condition('uid', $user
->id())
->condition('expires', $this->time
->getRequestTime(), '>')
->orderBy('created')
->execute();
while ($tokenArray = $tokensResult
->fetchAssoc()) {
$tokens[] = PersistentToken::createFromArray($tokenArray);
}
} catch (\Exception $e) {
$this->logger
->error('Unable to list tokens for user with uid @uid', [
'@uid' => $user
->id(),
]);
}
return $tokens;
}