Follow-up to #1433124: Suggested improvements in user_logout()

Proposed resolution

Greetings.
I have a suggestion for improvement for this function.
Soon after the session_destroy (), could be placed a drupal_set_message () to warn the user of the reason for the logout.
Would be as follows:

function user_logout($message = '', $status = 'warning') {
  global $user;

  watchdog('user', 'Session closed for %name.', array('%name' => $user->name));

  module_invoke_all('user_logout', $user);

  // Destroy the current session, and reset $user to the anonymous user.
  session_destroy();

 // Start
 // Sends a message to the user if you have a need to warn you
  if(!empty($message)){
      drupal_set_message($message, $status);
  }
 // End

  drupal_goto();
}

Why is this suggestion?
When I'm using hook_user_login and for some reason need to kill the session user can not I put after user_logout drupal_set_message () why there is a drupal_goto () and also no point in putting before why there is a session.destroy () which kills with the entire session.

The only way I saw to solve this is after putting session.destroy ().

[]'s

Comments

deivamagalhaes’s picture

StatusFileSize
new824 bytes

Just created the same patch on 7.x

dcam’s picture

Status: Needs work » Closed (duplicate)

I'm sorry, but it's unnecessary and counter-productive to create a second issue for 7.x. The other issue should be tagged as needing backport to 7.x instead. I know nothing has happened in that other issue for two years, but that's all the more reason we shouldn't be committing this to 7.x. New features must be added to Drupal 8 first, then backported. That's assuming the committer believes the feature can be added to 7.x at all.

jay.lee.bio’s picture

StatusFileSize
new1001 bytes

@deivamagalhaes: Thanks for the patch. For those interested, I just updated it to work on Drupal 7.50.

But eventually I thought it'd be better to create a module instead: https://www.drupal.org/sandbox/wwwjaylee/2791983