diff --git a/core/modules/user/src/PrivateTempStore.php b/core/modules/user/src/PrivateTempStore.php index 5491e92..3886fd9 100644 --- a/core/modules/user/src/PrivateTempStore.php +++ b/core/modules/user/src/PrivateTempStore.php @@ -12,6 +12,7 @@ use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Session\AccountProxyInterface; +use Symfony\Component\HttpFoundation\RequestStack; /** * Stores and retrieves temporary data for a given owner. @@ -56,6 +57,13 @@ class PrivateTempStore { protected $currentUser; /** + * The request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** * The time to live for items in seconds. * * By default, data is stored for one week (604800 seconds) before expiring. @@ -75,13 +83,16 @@ class PrivateTempStore { * The lock object used for this data. * @param \Drupal\Core\Session\AccountProxyInterface $current_user * The current user. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack. * @param int $expire * The time to live for items, in seconds. */ - public function __construct(KeyValueStoreExpirableInterface $storage, LockBackendInterface $lockBackend, AccountProxyInterface $current_user, $expire = 604800) { + public function __construct(KeyValueStoreExpirableInterface $storage, LockBackendInterface $lockBackend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) { $this->storage = $storage; $this->lockBackend = $lockBackend; $this->currentUser = $current_user; + $this->requestStack = $request_stack; $this->expire = $expire; } diff --git a/core/modules/user/src/PrivateTempStoreFactory.php b/core/modules/user/src/PrivateTempStoreFactory.php index 52abbda..39af0dc 100644 --- a/core/modules/user/src/PrivateTempStoreFactory.php +++ b/core/modules/user/src/PrivateTempStoreFactory.php @@ -39,6 +39,13 @@ class PrivateTempStoreFactory { protected $currentUser; /** + * The request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** * The time to live for items in seconds. * * @var int @@ -54,13 +61,16 @@ class PrivateTempStoreFactory { * The lock object used for this data. * @param \Drupal\Core\Session\AccountProxyInterface $current_user * The current user. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack. * @param int $expire * The time to live for items, in seconds. */ - function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lockBackend, AccountProxyInterface $current_user, $expire = 604800) { + function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lockBackend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) { $this->storageFactory = $storage_factory; $this->lockBackend = $lockBackend; $this->currentUser = $current_user; + $this->requestStack = $request_stack; $this->expire = $expire; } @@ -77,7 +87,7 @@ function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBac function get($collection) { // Store the data for this collection in the database. $storage = $this->storageFactory->get("user.private_tempstore.$collection"); - return new PrivateTempStore($storage, $this->lockBackend, $this->currentUser, $this->expire); + return new PrivateTempStore($storage, $this->lockBackend, $this->currentUser, $this->requestStack, $this->expire); } } diff --git a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php index bd71c9f..a2d3d95 100644 --- a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php @@ -10,6 +10,7 @@ use Drupal\Tests\UnitTestCase; use Drupal\user\PrivateTempStore; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * @coversDefaultClass \Drupal\user\PrivateTempStore @@ -46,6 +47,13 @@ class PrivateTempStoreTest extends UnitTestCase { protected $currentUser; /** + * The request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** * A tempstore object belonging to the owner. * * @var \stdClass @@ -72,9 +80,11 @@ protected function setUp() { ->method('id') ->willReturn(1); + $this->requestStack = new RequestStack(); $request = Request::createFromGlobals(); + $this->requestStack->push($request); - $this->tempStore = new PrivateTempStore($this->keyValue, $this->lock, $this->currentUser, 604800); + $this->tempStore = new PrivateTempStore($this->keyValue, $this->lock, $this->currentUser, $this->requestStack, 604800); $this->ownObject = (object) array( 'data' => 'test_data', diff --git a/core/modules/user/user.services.yml b/core/modules/user/user.services.yml index fb195b0..be4e679 100644 --- a/core/modules/user/user.services.yml +++ b/core/modules/user/user.services.yml @@ -50,7 +50,7 @@ services: arguments: ['@entity.manager', '@password'] user.private_tempstore: class: Drupal\user\PrivateTempStoreFactory - arguments: ['@keyvalue.expirable', '@lock', '@current_user', '%user.tempstore.expire%'] + arguments: ['@keyvalue.expirable', '@lock', '@current_user', '@request_stack', '%user.tempstore.expire%'] tags: - { name: backend_overridable } user.shared_tempstore: