function TempStore::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.

File

drupal/core/modules/user/lib/Drupal/user/TempStore.php, line 120
Contains Drupal\user\TempStore.

Class

TempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\user

Code

function setIfNotExists($key, $value) {
  $value = (object) array(
    'owner' => $this->owner,
    'data' => $value,
    'updated' => REQUEST_TIME,
  );
  return $this->storage
    ->setWithExpireIfNotExists($key, $value, $this->expire);
}