diff --git a/core/lib/Drupal/Core/Session/SessionManager.php b/core/lib/Drupal/Core/Session/SessionManager.php index 52b3542..3c71930 100644 --- a/core/lib/Drupal/Core/Session/SessionManager.php +++ b/core/lib/Drupal/Core/Session/SessionManager.php @@ -174,6 +174,7 @@ protected function startNow() { // Restore session data. if ($this->startedLazy) { $_SESSION = $session_data; + $this->loadSession(); } return $result; diff --git a/core/modules/system/src/Tests/Session/SessionTest.php b/core/modules/system/src/Tests/Session/SessionTest.php index 75b194a..3f26ee9 100644 --- a/core/modules/system/src/Tests/Session/SessionTest.php +++ b/core/modules/system/src/Tests/Session/SessionTest.php @@ -100,6 +100,10 @@ function testDataPersistence() { $this->drupalGet('session-test/get'); $this->assertText($value_1, 'Session data is not saved for drupal_save_session(FALSE).', 'Session'); + // Test property added to session object form hook_user_login(). + $this->drupalGet('session-test/get-from-session-object'); + $this->assertText('foobar', 'Session data is saved in Session() object.', 'Session'); + // Switch browser cookie to anonymous user, then back to user 1. $this->sessionReset(); $this->sessionReset($user->id()); diff --git a/core/modules/system/tests/modules/session_test/session_test.module b/core/modules/system/tests/modules/session_test/session_test.module index 0fb2ae4..6a08211 100644 --- a/core/modules/system/tests/modules/session_test/session_test.module +++ b/core/modules/system/tests/modules/session_test/session_test.module @@ -9,4 +9,6 @@ function session_test_user_login($account) { // before hook_user_login() was called. exit; } + // Add some data in the session for retrieval testing purpose. + \Drupal::request()->getSession()->set("session_test_key", "foobar"); } diff --git a/core/modules/system/tests/modules/session_test/session_test.routing.yml b/core/modules/system/tests/modules/session_test/session_test.routing.yml index 8b9393e..fce0fc9 100644 --- a/core/modules/system/tests/modules/session_test/session_test.routing.yml +++ b/core/modules/system/tests/modules/session_test/session_test.routing.yml @@ -5,7 +5,13 @@ session_test.get: _controller: '\Drupal\session_test\Controller\SessionTestController::get' requirements: _access: 'TRUE' - +session_test.get_from_session_object: + path: '/session-test/get-from-session-object' + defaults: + _title: 'Session value' + _controller: '\Drupal\session_test\Controller\SessionTestController::getFromSessionObject' + requirements: + _access: 'TRUE' session_test.id: path: '/session-test/id' defaults: diff --git a/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php b/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php index 1ae9a79..2db6f21 100644 --- a/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php +++ b/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php @@ -31,6 +31,19 @@ public function get() { } /** + * Prints the stored session value to the screen. + * + * @return string + * A notification message. + */ + public function getFromSessionObject() { + $value = \Drupal::request()->getSession()->get("session_test_key"); + return empty($value) + ? [] + : ['#markup' => $this->t('The current value of the stored session variable is: %val', array('%val' => $value))]; + } + + /** * Print the current session ID. * * @return string