Chris@0: storageFactory = $storage_factory; Chris@0: $this->lockBackend = $lock_backend; Chris@0: $this->requestStack = $request_stack; Chris@0: $this->expire = $expire; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a SharedTempStore for the current user or anonymous session. Chris@0: * Chris@0: * @param string $collection Chris@0: * The collection name to use for this key/value store. This is typically Chris@0: * a shared namespace or module name, e.g. 'views', 'entity', etc. Chris@0: * @param mixed $owner Chris@0: * (optional) The owner of this SharedTempStore. By default, the Chris@0: * SharedTempStore is owned by the currently authenticated user, or by the Chris@0: * active anonymous session if no user is logged in. Chris@0: * Chris@0: * @return \Drupal\user\SharedTempStore Chris@0: * An instance of the key/value store. Chris@0: */ Chris@0: public function get($collection, $owner = NULL) { Chris@0: // Use the currently authenticated user ID or the active user ID unless Chris@0: // the owner is overridden. Chris@0: if (!isset($owner)) { Chris@0: $owner = \Drupal::currentUser()->id() ?: session_id(); Chris@0: } Chris@0: Chris@0: // Store the data for this collection in the database. Chris@0: $storage = $this->storageFactory->get("user.shared_tempstore.$collection"); Chris@0: return new SharedTempStore($storage, $this->lockBackend, $owner, $this->requestStack, $this->expire); Chris@0: } Chris@0: Chris@0: }