You are here

protected function WebformSubmissionStorage::doSave in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformSubmissionStorage.php \Drupal\webform\WebformSubmissionStorage::doSave()

Performs storage-specific saving of the entity.

Parameters

int|string $id: The original entity ID.

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

Return value

bool|int If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides ContentEntityStorageBase::doSave

1 call to WebformSubmissionStorage::doSave()
WebformSubmissionStorage::resave in src/WebformSubmissionStorage.php
Resaves the entity without triggering any hooks or handlers.

File

src/WebformSubmissionStorage.php, line 986

Class

WebformSubmissionStorage
Defines the webform submission storage.

Namespace

Drupal\webform

Code

protected function doSave($id, EntityInterface $entity) {

  /** @var \Drupal\webform\WebformSubmissionInterface $entity */
  if ($entity
    ->getWebform()
    ->getSetting('results_disabled')) {
    return WebformSubmissionStorageInterface::SAVED_DISABLED;
  }
  $is_new = $entity
    ->isNew();
  $result = parent::doSave($id, $entity);

  // Save data.
  $this
    ->saveData($entity, !$is_new);

  // Set serial number to the submission id.
  if (!$entity
    ->serial() && $entity
    ->getWebform()
    ->getSetting('serial_disabled')) {
    $this->database
      ->update('webform_submission')
      ->fields([
      'serial' => $entity
        ->id(),
    ])
      ->condition('sid', $entity
      ->id())
      ->execute();
    $entity
      ->set('serial', $entity
      ->id());
  }

  // Set anonymous draft token.
  // This only needs to be called for new anonymous submissions.
  if ($is_new) {
    $this
      ->setAnonymousSubmission($entity);
  }
  return $result;
}