function user_default_page_user_logout in User Default Page 8
Same name and namespace in other branches
- 8.2 user_default_page.module \user_default_page_user_logout()
Implements hook_user_logout().
File
- ./
user_default_page.module, line 47 - Contains user_default_page.module..
Code
function user_default_page_user_logout($account) {
// Load all entities belongs to "user_default_page_config_entity".
$entities_load = \Drupal::entityTypeManager()
->getStorage('user_default_page_config_entity')
->loadMultiple();
// Get User Role(s).
$roles = $account
->getRoles();
$uid = $account
->id();
$logout_redirect = '';
$logout_message = '';
$current_weight = NULL;
// Check for redirect logout path.
foreach ($entities_load as $entity) {
if (array_intersect($entity
->getUserRoles(), $roles)) {
if ($current_weight < $entity
->getWeight()) {
$current_weight = $entity
->getWeight();
$logout_redirect = $entity
->getLogoutRedirect();
}
$logout_message = $entity
->getLogoutRedirectMessage();
}
$users_array = $entity
->getUsers();
if (strpos($users_array, $uid . ',') !== FALSE) {
$logout_redirect = $entity
->getLogoutRedirect();
$logout_message = $entity
->getLogoutRedirectMessage();
}
}
if ($logout_redirect && !empty($logout_message)) {
// Set Logout redirect message.
drupal_set_message(t($logout_message));
user_default_page_redirect($logout_redirect);
}
}