After my user is submitting a form, I want to logged him out, then redirect to the front page. then, display a message.
public function submitForm(array &$form, FormStateInterface $form_state) {
/**
* my logic
**/
if ($isDeleted) {
$this->messenger()->addMessage('Logged out');
user_logout();
$home = \Drupal\Core\Url::fromRoute('<front>')->setAbsolute();
$form_state->setRedirectUrl($home);
}
}
This code works fine, but the message doesn't show up. I read/assumed that the messenger is linked to the current session, so by log out the user, the messenger is destroyed.
So I tried to create another messenger after the user logout, but still, the message isn't displayed.