diff --git a/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php b/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php index 0a1cd4249f..98ce7efa4b 100644 --- a/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php +++ b/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php @@ -7,7 +7,6 @@ use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Session\AccountProxyInterface; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * Creates a shared temporary storage for a collection. @@ -67,12 +66,10 @@ class SharedTempStoreFactory { * The request stack. * @param \Drupal\Core\Session\AccountProxyInterface $current_user * The current user. - * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session - * The session service. * @param int $expire * The time to live for items, in seconds. */ - public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $current_user = NULL, SessionInterface $session = NULL, $expire = 604800) { + public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $current_user = NULL, $expire = 604800) { $this->storageFactory = $storage_factory; $this->lockBackend = $lock_backend; $this->requestStack = $request_stack; @@ -82,14 +79,8 @@ public function __construct(KeyValueExpirableFactoryInterface $storage_factory, else { $this->currentUser = \Drupal::currentUser(); } - if ($session instanceof SessionInterface) { - $this->session = $session; - } - else { - $this->session = \Drupal::service('session'); - } - if (!($current_user instanceof AccountProxyInterface) || !($session instanceof SessionInterface)) { - @trigger_error(__CLASS__ . '::__construct() now requires the current_user and session services to be injected. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); + if (!($current_user instanceof AccountProxyInterface)) { + @trigger_error(__CLASS__ . '::__construct() now requires the current_user to be injected. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); if (is_int($current_user)) { // If the $current_user argument is numeric then this object has been // instantiated with the old constructor signature. @@ -119,15 +110,12 @@ public function get($collection, $owner = NULL) { if (!isset($owner)) { $owner = $this->currentUser->id(); if ($this->currentUser->isAnonymous()) { - $has_session = $this->requestStack - ->getCurrentRequest() - ->hasSession(); - if (!$has_session) { - $this->requestStack->getCurrentRequest()->setSession($this->session); - $this->session->start(); + $owner = Crypt::randomBytesBase64(); + if ($this->requestStack->getCurrentRequest()->hasSession()) { + // Anonymous users store a random identifier in session if session is + // available. + $owner = $this->requestStack->getCurrentRequest()->getSession()->get('core.tempstore.shared.owner', $owner); } - // Anonymous users store a random identifier in session. - $owner = $this->requestStack->getCurrentRequest()->getSession()->get('core.tempstore.shared.owner', Crypt::randomBytesBase64()); } } diff --git a/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php b/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php index d3273748dc..01cf2db014 100644 --- a/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php @@ -71,8 +71,7 @@ public function testSharedTempStore() { new KeyValueExpirableFactory(\Drupal::getContainer()), new DatabaseLockBackend($database), $this->container->get('request_stack'), - $current_user->reveal(), - $this->container->get('session') + $current_user->reveal() ); $collection = $this->randomMachineName();