public function AutologoutManager::getUserRedirectUrl in Automated Logout 8
Get a user's logout URL.
Parameters
null|int $uid: User id or NULL to use current logged in user.
Return value
null|string User's logout URL or NULL for anonymous user.
Overrides AutologoutManagerInterface::getUserRedirectUrl
File
- src/
AutologoutManager.php, line 321
Class
- AutologoutManager
- Defines an AutologoutManager service.
Namespace
Drupal\autologoutCode
public function getUserRedirectUrl($uid = NULL) {
if (is_null($uid)) {
// If $uid is not provided, use the logged in user.
$user = $this->entityTypeManager
->getStorage('user')
->load($this->currentUser
->id());
}
else {
$user = $this->entityTypeManager
->getStorage('user')
->load($uid);
}
if ($user
->id() == 0) {
// Anonymous doesn't get logged out.
return;
}
// Get role timeouts for user.
if ($this->autoLogoutSettings
->get('role_logout')) {
$user_roles = $user
->getRoles();
$output = [];
$urls = $this
->getRoleUrl();
foreach ($user_roles as $rid => $role) {
if (isset($urls[$role])) {
$output[$rid] = $urls[$role];
}
}
// Assign the first matching Role.
if (!empty($output) && !empty(reset($output))) {
// If one of the user's roles has a unique URL, use this.
return reset($output);
}
}
// If no user or role override exists, return the default timeout.
return $this->autoLogoutSettings
->get('redirect_url');
}