You are here

public function WebformSubmission::createDuplicate in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Entity/WebformSubmission.php \Drupal\webform\Entity\WebformSubmission::createDuplicate()

Creates a duplicate of the entity.

Return value

static A clone of $this with all identifiers unset, so saving it inserts a new entity into the storage system.

Overrides ContentEntityBase::createDuplicate

File

src/Entity/WebformSubmission.php, line 734

Class

WebformSubmission
Defines the WebformSubmission entity.

Namespace

Drupal\webform\Entity

Code

public function createDuplicate() {

  /** @var \Drupal\webform\WebformSubmissionInterface $duplicate */
  $duplicate = parent::createDuplicate();
  $duplicate
    ->set('serial', NULL);
  $duplicate
    ->set('token', Crypt::randomBytesBase64());

  // Clear state.
  $duplicate
    ->set('in_draft', FALSE);
  $duplicate
    ->set('current_page', NULL);

  // Create timestamps.
  $duplicate
    ->set('created', NULL);
  $duplicate
    ->set('changed', NULL);
  $duplicate
    ->set('completed', NULL);

  // Clear admin notes, sticky, and locked.
  $duplicate
    ->set('notes', '');
  $duplicate
    ->set('sticky', FALSE);
  $duplicate
    ->set('locked', FALSE);
  return $duplicate;
}