function TempStoreFactory::get

Creates a TempStore 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 TempStore. By default, the TempStore is owned by the currently authenticated user, or by the active anonymous session if no user is logged in.

Return value

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

File

drupal/core/modules/user/lib/Drupal/user/TempStoreFactory.php, line 60
Definition of Drupal\user\TempStoreFactory.

Class

TempStoreFactory
Creates a key/value storage object for the current user or anonymous session.

Namespace

Drupal\user

Code

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 = $GLOBALS['user']->uid ?: session_id();
  }

  // Store the data for this collection in the database.
  $storage = new DatabaseStorageExpirable($collection, $this->connection);
  return new TempStore($storage, $this->lockBackend, $owner);
}