function SharedTempStore::ensureAnonymousSession

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::ensureAnonymousSession()
  2. 11.x core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::ensureAnonymousSession()

Stores the owner in the session if the user is anonymous.

This method should be called when a value is set.

2 calls to SharedTempStore::ensureAnonymousSession()
SharedTempStore::set in core/lib/Drupal/Core/TempStore/SharedTempStore.php
Stores a particular key/value pair in this SharedTempStore.
SharedTempStore::setIfNotExists in core/lib/Drupal/Core/TempStore/SharedTempStore.php
Stores a particular key/value pair only if the key doesn't already exist.

File

core/lib/Drupal/Core/TempStore/SharedTempStore.php, line 310

Class

SharedTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\Core\TempStore

Code

protected function ensureAnonymousSession() {
    // If this is being run from the CLI then the request will not have a
    // session.
    if ($this->currentUser
        ->isAnonymous() && $this->requestStack
        ->getCurrentRequest()
        ->hasSession()) {
        $this->requestStack
            ->getCurrentRequest()
            ->getSession()
            ->set('core.tempstore.shared.owner', $this->owner);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.