protected function KeyValueEntityStorage::doSave in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage::doSave()
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 173
Class
- KeyValueEntityStorage
- Provides a key value backend for entities.
Namespace
Drupal\Core\Entity\KeyValueStoreCode
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;
}