You are here

protected function ParagraphLineageRevisioner::doSaveNewRevision in Paragraphs Edit 8.2

Saves an entity as a new revision.

Parameters

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

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

1 call to ParagraphLineageRevisioner::doSaveNewRevision()
ParagraphLineageRevisioner::saveNewRevision in src/ParagraphLineageRevisioner.php
Saves all of given entity's lineage as new revisions.

File

src/ParagraphLineageRevisioner.php, line 73

Class

ParagraphLineageRevisioner
ParagraphLineageRevisioner class.

Namespace

Drupal\paragraphs_edit

Code

protected function doSaveNewRevision(ContentEntityInterface $entity) {

  // Get the parent field item before saving, as after saving the
  // revision ID will be changed.
  if ($entity instanceof ParagraphInterface) {
    $parent_field_item = $this->lineageInspector
      ->getParentFieldItem($entity);
  }
  try {
    $entity
      ->setNewRevision();
  } catch (\LogicException $e) {

    // A content entity not necessarily supports revisioning.
  }
  $status = $entity
    ->save();
  if (isset($parent_field_item)) {
    $parent_field_item
      ->set('target_revision_id', $entity
      ->getRevisionId());
  }
  return $status;
}