function SharedTempStore::setIfOwner
Same name in other branches
- 8.9.x core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::setIfOwner()
- 10 core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::setIfOwner()
- 11.x core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\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.
Throws
\Drupal\Core\TempStore\TempStoreException Thrown when a lock for the backend storage could not be acquired.
File
-
core/
lib/ Drupal/ Core/ TempStore/ SharedTempStore.php, line 196
Class
- SharedTempStore
- Stores and retrieves temporary data for a given owner.
Namespace
Drupal\Core\TempStoreCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.