You are here

public function SharedTempStoreFactory::get in Drupal 8

Same name in this branch
  1. 8 core/modules/user/src/SharedTempStoreFactory.php \Drupal\user\SharedTempStoreFactory::get()
  2. 8 core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php \Drupal\Core\TempStore\SharedTempStoreFactory::get()

Creates a SharedTempStore for the current user or anonymous session.

Parameters

string $collection: The collection name to use for this key/value store. This is typically a shared namespace or module name, e.g. 'views', 'entity', etc.

mixed $owner: (optional) The owner of this SharedTempStore. By default, the SharedTempStore is owned by the currently authenticated user, or by the active anonymous session if no user is logged in.

Return value

\Drupal\user\SharedTempStore An instance of the key/value store.

Overrides SharedTempStoreFactory::get

File

core/modules/user/src/SharedTempStoreFactory.php, line 34

Class

SharedTempStoreFactory
Creates a shared temporary storage for a collection.

Namespace

Drupal\user

Code

public function get($collection, $owner = NULL) {

  // Use the currently authenticated user ID or the active user ID unless
  // the owner is overridden.
  if (!isset($owner)) {
    $owner = \Drupal::currentUser()
      ->id() ?: session_id();
  }

  // Store the data for this collection in the database.
  $storage = $this->storageFactory
    ->get("user.shared_tempstore.{$collection}");
  return new SharedTempStore($storage, $this->lockBackend, $owner, $this->requestStack, $this->expire);
}