You are here

protected function PrivateTempStore::startSession in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TempStore/PrivateTempStore.php \Drupal\Core\TempStore\PrivateTempStore::startSession()

Start session because it is required for a private temp store.

Ensures that an anonymous user has a session created for them, as otherwise subsequent page loads will not be able to retrieve their tempstore data.

@todo when https://www.drupal.org/node/2865991 is resolved, use force start session API.

2 calls to PrivateTempStore::startSession()
PrivateTempStore::getOwner in core/lib/Drupal/Core/TempStore/PrivateTempStore.php
Gets the current owner based on the current user or the session ID.
PrivateTempStore::set in core/lib/Drupal/Core/TempStore/PrivateTempStore.php
Stores a particular key/value pair in this PrivateTempStore.

File

core/lib/Drupal/Core/TempStore/PrivateTempStore.php, line 243

Class

PrivateTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\Core\TempStore

Code

protected function startSession() {
  $has_session = $this->requestStack
    ->getCurrentRequest()
    ->hasSession();
  if (!$has_session) {

    /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
    $session = \Drupal::service('session');
    $this->requestStack
      ->getCurrentRequest()
      ->setSession($session);
    $session
      ->start();
  }
}