function KeyValueEntityStorage::doSave

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage::doSave()
  2. 10 core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage::doSave()
  3. 11.x core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage::doSave()

Overrides EntityStorageBase::doSave

File

core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php, line 174

Class

KeyValueEntityStorage
Provides a key value backend for entities.

Namespace

Drupal\Core\Entity\KeyValueStore

Code

protected function doSave($id, EntityInterface $entity) {
    $is_new = $entity->isNew();
    // Save the entity data in the key value store.
    $this->keyValueStore
        ->set($entity->id(), $entity->toArray());
    // If this is a rename, delete the original entity.
    if ($this->has($id, $entity) && $id !== $entity->id()) {
        $this->keyValueStore
            ->delete($id);
    }
    return $is_new ? SAVED_NEW : SAVED_UPDATED;
}

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