- 🇮🇳India amitajgaonkar
For Drupal 10 #4 and #6 does not work. during hook_user_login session is not created.
- 🇮🇳India itsbakiya
$session->getID() is empty. Is there any other way to get the session value
- 🇧🇪Belgium paulvb
I had the same issue for a very specific use case. It's a bit of a hack, but I discovered that you can initiate the session and access the session ID by calling \Drupal::currentUser()->getAccount(); within the user_login hook and then session service will return the id...
In drupal 9 session manager had a method getid that generated one if none was present. https://www.drupal.org/node/3006306 →
public function getId() {
$id = parent::getId();if (empty($id)) {
// Legacy code might rely on the existence of a session ID before a real
// session exists. In this case, generate a random session ID to provide
// backwards compatibility.
@trigger_error('Calling ' . __METHOD__ . '() outside of an actual existing session is deprecated in drupal:9.2.0 and will be removed in drupal:10.0.0. This is often used for anonymous users. See https://www.drupal.org/node/3006306 → ', E_USER_DEPRECATED);
$id = Crypt::randomBytesBase64();
$this->setId($id);
}
return $id;
}