function SharedTempStore::deleteIfOwner

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

Deletes data from the store for a given key and releases the lock on it.

Only delete the given key if it is owned by $this->owner.

Parameters

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

Return value

bool TRUE if the object was deleted or does not exist, FALSE if it exists but is not owned by $this->owner.

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 293

Class

SharedTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\Core\TempStore

Code

public function deleteIfOwner($key) {
    if (!($object = $this->storage
        ->get($key))) {
        return TRUE;
    }
    elseif ($object->owner == $this->owner) {
        $this->delete($key);
        return TRUE;
    }
    return FALSE;
}

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