You are here

protected function ParagraphDeleteForm::doSaveNewRevision in Paragraphs table 8

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 ParagraphDeleteForm::doSaveNewRevision()
ParagraphDeleteForm::saveNewRevision in src/Form/ParagraphDeleteForm.php
Saves all of given entity's lineage as new revisions.

File

src/Form/ParagraphDeleteForm.php, line 168

Class

ParagraphDeleteForm
Provides a form for deleting a paragraph from a node.

Namespace

Drupal\paragraphs_table\Form

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
      ->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;
}