Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / user / src / SharedTempStoreFactory.php
1 <?php
2
3 namespace Drupal\user;
4
5 use Drupal\Core\TempStore\SharedTempStoreFactory as CoreSharedTempStoreFactory;
6
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);
8
9 /**
10  * Creates a shared temporary storage for a collection.
11  *
12  * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
13  *   Use \Drupal\Core\TempStore\SharedTempStoreFactory instead.
14  *
15  * @see \Drupal\Core\TempStore\SharedTempStoreFactory
16  * @see https://www.drupal.org/node/2935639
17  */
18 class SharedTempStoreFactory extends CoreSharedTempStoreFactory {
19
20   /**
21    * Creates a SharedTempStore for the current user or anonymous session.
22    *
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.
26    * @param mixed $owner
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.
30    *
31    * @return \Drupal\user\SharedTempStore
32    *   An instance of the key/value store.
33    */
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.
37     if (!isset($owner)) {
38       $owner = \Drupal::currentUser()->id() ?: session_id();
39     }
40
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);
44   }
45
46 }