function SharedTempStore::setIfNotExists

Same name in other branches
  1. 9 core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::setIfNotExists()
  2. 8.9.x core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::setIfNotExists()
  3. 11.x core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::setIfNotExists()

Stores a particular key/value pair only if the key doesn't already exist.

Parameters

string $key: The key of the data to check and store.

mixed $value: The data to store.

Return value

bool TRUE if the data was set, or FALSE if it already existed.

1 call to SharedTempStore::setIfNotExists()
SharedTempStore::setIfOwner in core/lib/Drupal/Core/TempStore/SharedTempStore.php
Stores a particular key/value pair in this SharedTempStore.

File

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

Class

SharedTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\Core\TempStore

Code

public function setIfNotExists($key, $value) {
    $value = (object) [
        'owner' => $this->owner,
        'data' => $value,
        'updated' => (int) $this->requestStack
            ->getMainRequest()->server
            ->get('REQUEST_TIME'),
    ];
    $this->ensureAnonymousSession();
    $set = $this->storage
        ->setWithExpireIfNotExists($key, $value, $this->expire);
    return $set;
}

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