5 use Drupal\Core\TempStore\SharedTempStoreFactory as CoreSharedTempStoreFactory;
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);
10 * Creates a shared temporary storage for a collection.
12 * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
13 * Use \Drupal\Core\TempStore\SharedTempStoreFactory instead.
15 * @see \Drupal\Core\TempStore\SharedTempStoreFactory
16 * @see https://www.drupal.org/node/2935639
18 class SharedTempStoreFactory extends CoreSharedTempStoreFactory {
21 * Creates a SharedTempStore for the current user or anonymous session.
23 * @param string $collection
24 * The collection name to use for this key/value store. This is typically
25 * a shared namespace or module name, e.g. 'views', 'entity', etc.
27 * (optional) The owner of this SharedTempStore. By default, the
28 * SharedTempStore is owned by the currently authenticated user, or by the
29 * active anonymous session if no user is logged in.
31 * @return \Drupal\user\SharedTempStore
32 * An instance of the key/value store.
34 public function get($collection, $owner = NULL) {
35 // Use the currently authenticated user ID or the active user ID unless
36 // the owner is overridden.
38 $owner = \Drupal::currentUser()->id() ?: session_id();
41 // Store the data for this collection in the database.
42 $storage = $this->storageFactory->get("user.shared_tempstore.$collection");
43 return new SharedTempStore($storage, $this->lockBackend, $owner, $this->requestStack, $this->expire);