function SessionExampleForm::submitClearSession
Same name in other branches
- 8.x-1.x session_example/src/Form/SessionExampleForm.php \Drupal\session_example\Form\SessionExampleForm::submitClearSession()
- 4.0.x modules/session_example/src/Form/SessionExampleForm.php \Drupal\session_example\Form\SessionExampleForm::submitClearSession()
Remove all the session information.
File
-
modules/
session_example/ src/ Form/ SessionExampleForm.php, line 170
Class
- SessionExampleForm
- Form to allow the user to store information in their session.
Namespace
Drupal\session_example\FormCode
public function submitClearSession(array &$form, FormStateInterface $form_state) {
$items = [
'session_example.name',
'session_example.email',
'session_example.quest',
'session_example.color',
];
foreach ($items as $item) {
$this->session
->remove($item);
}
$this->messenger()
->addMessage($this->t('Session is cleared.'));
// Since we might have changed the session information, we will invalidate
// the cache tag for this session.
$this->invalidateCacheTag();
}