You are here

public function SharedTempStore::setIfOwner in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/SharedTempStore.php \Drupal\user\SharedTempStore::setIfOwner()

Stores a particular key/value pair in this SharedTempStore.

Only stores the given key/value pair if it does not exist yet or is owned by $this->owner.

Parameters

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

mixed $value: The data to store.

Return value

bool TRUE if the data was set, or FALSE if it already exists and is not owned by $this->user.

File

core/modules/user/src/SharedTempStore.php, line 173
Contains \Drupal\user\SharedTempStore.

Class

SharedTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\user

Code

public function setIfOwner($key, $value) {
  if ($this
    ->setIfNotExists($key, $value)) {
    return TRUE;
  }
  if (($object = $this->storage
    ->get($key)) && $object->owner == $this->owner) {
    $this
      ->set($key, $value);
    return TRUE;
  }
  return FALSE;
}