public function UserController::listTokens in Persistent Login 8
List users's active tokens.
Parameters
\Drupal\user\UserInterface $user: The user account object.
Return value
string Render array with list of user's active tokens. Render array with list of user's active tokens.
1 string reference to 'UserController::listTokens'
File
- src/
Controller/ UserController.php, line 73
Class
- UserController
- Class UserTokens.
Namespace
Drupal\persistent_login\ControllerCode
public function listTokens(UserInterface $user) {
$config = $this
->config('persistent_login.settings');
$configuredLifetime = $config
->get('lifetime');
$render['tokens'] = [
'#type' => 'table',
'#header' => [
$this
->t('Created'),
$this
->t('Last Used'),
],
'#empty' => $this
->t('No persistent logins have been created.'),
];
if ($configuredLifetime !== 0) {
$render['tokens']['#header'][] = $this
->t('Expires');
}
$tokens = $this->tokenManager
->getTokensForUser($user);
foreach ($tokens as $token) {
$row = [
'created' => [
'#markup' => $this->dateFormatter
->format($token
->getCreated()
->getTimestamp()),
],
'refreshed' => [
'#markup' => $this->dateFormatter
->format($token
->getRefreshed()
->getTimestamp()),
],
];
if ($configuredLifetime !== 0) {
$row['expires'] = [
'#markup' => $this->dateFormatter
->format($token
->getExpiry()
->getTimestamp()),
];
}
$render['tokens'][] = $row;
}
return $render;
}