function ContentEntityStorageBase::doSave

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::doSave()
  2. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::doSave()
  3. 9 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::doSave()

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 637

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function doSave($id, EntityInterface $entity) {
  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  if ($entity->isNew()) {
    // Ensure the entity is still seen as new after assigning it an id, while
    // storing its data.
    $entity->enforceIsNew();
    if ($this->entityType
      ->isRevisionable()) {
      $entity->setNewRevision();
    }
    $return = SAVED_NEW;
  }
  else {
    // @todo Consider returning a different value when saving a non-default
    //   entity revision. See https://www.drupal.org/node/2509360.
    $return = $entity->isDefaultRevision() ? SAVED_UPDATED : FALSE;
  }
  $this->populateAffectedRevisionTranslations($entity);
  // Populate the "revision_default" flag. We skip this when we are resaving
  // the revision because this is only allowed for default revisions, and
  // these cannot be made non-default.
  if ($this->entityType
    ->isRevisionable() && $entity->isNewRevision()) {
    $revision_default_key = $this->entityType
      ->getRevisionMetadataKey('revision_default');
    $entity->set($revision_default_key, $entity->isDefaultRevision());
  }
  $this->doSaveFieldItems($entity);
  return $return;
}

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