function SqlContentEntityStorage::save

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::save()
  2. 8.9.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::save()
  3. 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::save()

Overrides EntityStorageBase::save

1 method overrides SqlContentEntityStorage::save()
MediaStorage::save in core/modules/media/src/MediaStorage.php
Saves the entity permanently.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php, line 802

Class

SqlContentEntityStorage
A content entity database storage implementation.

Namespace

Drupal\Core\Entity\Sql

Code

public function save(EntityInterface $entity) {
    try {
        $transaction = $this->database
            ->startTransaction();
        $return = parent::save($entity);
        // Ignore replica server temporarily.
        \Drupal::service('database.replica_kill_switch')->trigger();
        return $return;
    } catch (\Exception $e) {
        if (isset($transaction)) {
            $transaction->rollBack();
        }
        Error::logException(\Drupal::logger($this->entityTypeId), $e);
        throw new EntityStorageException($e->getMessage(), $e->getCode(), $e);
    }
}

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