You are here

protected function ContentEntityStorageTrait::doSave in Multiversion 8

Same name and namespace in other branches
  1. 8.2 src/Entity/Storage/ContentEntityStorageTrait.php \Drupal\multiversion\Entity\Storage\ContentEntityStorageTrait::doSave()

@todo Revisit this logic with forward revisions in mind.

File

src/Entity/Storage/ContentEntityStorageTrait.php, line 440

Class

ContentEntityStorageTrait

Namespace

Drupal\multiversion\Entity\Storage

Code

protected function doSave($id, EntityInterface $entity) {
  if ($entity->_rev->is_stub || $this->entityType
    ->get('local') || !empty($entity->original) && $entity->original->_rev->is_stub) {
    $entity
      ->isDefaultRevision(TRUE);
  }
  else {

    // Enforce new revision if any module messed with it in a hook.
    $entity
      ->setNewRevision();

    // Decide whether or not this is the default revision.
    if (!$entity
      ->isNew()) {
      $workspace = isset($entity->workspace) ? $entity->workspace->entity : null;
      $index_factory = \Drupal::service('multiversion.entity_index.factory');

      /** @var \Drupal\multiversion\Entity\Index\RevisionTreeIndexInterface $tree */
      $tree = $index_factory
        ->get('multiversion.entity_index.rev.tree', $workspace);
      $default_rev = $tree
        ->getDefaultRevision($entity
        ->uuid());
      if ($entity->_rev->value == $default_rev) {
        $entity
          ->isDefaultRevision(TRUE);
      }
      else {
        $entity
          ->isDefaultRevision(FALSE);
      }
    }
  }
  return parent::doSave($id, $entity);
}