Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\user;
|
Chris@0
|
4
|
Chris@14
|
5 use Drupal\Core\TempStore\SharedTempStoreFactory as CoreSharedTempStoreFactory;
|
Chris@14
|
6
|
Chris@14
|
7 @trigger_error('\Drupal\user\SharedTempStoreFactory is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStoreFactory instead. See https://www.drupal.org/node/2935639.', E_USER_DEPRECATED);
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Creates a shared temporary storage for a collection.
|
Chris@14
|
11 *
|
Chris@14
|
12 * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
|
Chris@14
|
13 * Use \Drupal\Core\TempStore\SharedTempStoreFactory instead.
|
Chris@14
|
14 *
|
Chris@14
|
15 * @see \Drupal\Core\TempStore\SharedTempStoreFactory
|
Chris@14
|
16 * @see https://www.drupal.org/node/2935639
|
Chris@0
|
17 */
|
Chris@14
|
18 class SharedTempStoreFactory extends CoreSharedTempStoreFactory {
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@0
|
21 * Creates a SharedTempStore for the current user or anonymous session.
|
Chris@0
|
22 *
|
Chris@0
|
23 * @param string $collection
|
Chris@0
|
24 * The collection name to use for this key/value store. This is typically
|
Chris@0
|
25 * a shared namespace or module name, e.g. 'views', 'entity', etc.
|
Chris@0
|
26 * @param mixed $owner
|
Chris@0
|
27 * (optional) The owner of this SharedTempStore. By default, the
|
Chris@0
|
28 * SharedTempStore is owned by the currently authenticated user, or by the
|
Chris@0
|
29 * active anonymous session if no user is logged in.
|
Chris@0
|
30 *
|
Chris@0
|
31 * @return \Drupal\user\SharedTempStore
|
Chris@0
|
32 * An instance of the key/value store.
|
Chris@0
|
33 */
|
Chris@0
|
34 public function get($collection, $owner = NULL) {
|
Chris@0
|
35 // Use the currently authenticated user ID or the active user ID unless
|
Chris@0
|
36 // the owner is overridden.
|
Chris@0
|
37 if (!isset($owner)) {
|
Chris@0
|
38 $owner = \Drupal::currentUser()->id() ?: session_id();
|
Chris@0
|
39 }
|
Chris@0
|
40
|
Chris@0
|
41 // Store the data for this collection in the database.
|
Chris@0
|
42 $storage = $this->storageFactory->get("user.shared_tempstore.$collection");
|
Chris@0
|
43 return new SharedTempStore($storage, $this->lockBackend, $owner, $this->requestStack, $this->expire);
|
Chris@0
|
44 }
|
Chris@0
|
45
|
Chris@0
|
46 }
|