You are here

protected function ParagraphCloneForm::prepareEntity in Paragraphs Edit 8

Prepares the entity object before the form is built first.

Overrides ContentEntityForm::prepareEntity

File

src/ParagraphCloneForm.php, line 21

Class

ParagraphCloneForm

Namespace

Drupal\paragraphs_edit

Code

protected function prepareEntity() {
  parent::prepareEntity();
  $account = \Drupal::currentUser();
  $uuid_generator = \Drupal::service('uuid');

  // Create clone of this entity
  $this->originalEntity = clone $this->entity;

  /** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
  $paragraph = $this->entity;

  // Make sure this paragraph is treated as a new one.
  $paragraph
    ->enforceIsNew();
  $paragraph
    ->setNewRevision(TRUE);
  $paragraph
    ->set('id', NULL);
  $paragraph
    ->set('revision_id', NULL);
  $paragraph
    ->set('uuid', $uuid_generator
    ->generate());
  $paragraph
    ->set('created', REQUEST_TIME);
  $paragraph
    ->setOwnerId($account
    ->id());
  $paragraph
    ->setRevisionAuthorId($account
    ->id());
}