KeyValueEntityStorage::doSave

protected KeyValueEntityStorage::doSave($id, EntityInterface $entity)

Performs storage-specific saving of the entity.

Parameters

int|string $id: The original entity ID.

\Drupal\Core\Entity\EntityInterface $entity: The entity to save.

Return value

bool|int If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides EntityStorageBase::doSave

File

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

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;
}
doc_Drupal
2016-10-29 09:21:45
Comments
Leave a Comment

Please login to continue.