You are here

public function WebformSubmissionStorage::loadDraft in Webform 8.5

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

Get webform submission draft.

Parameters

\Drupal\webform\WebformInterface|null $webform: A webform.

\Drupal\Core\Entity\EntityInterface|null $source_entity: A webform submission source entity.

\Drupal\Core\Session\AccountInterface|null $account: A user account.

Return value

\Drupal\webform\WebformSubmissionInterface A webform submission.

Overrides WebformSubmissionStorageInterface::loadDraft

File

src/WebformSubmissionStorage.php, line 1481

Class

WebformSubmissionStorage
Defines the webform submission storage.

Namespace

Drupal\webform

Code

public function loadDraft(WebformInterface $webform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
  $options = [
    'check_source_entity' => TRUE,
    'in_draft' => TRUE,
  ];
  $query = $this
    ->getQuery();

  // Because draft is somewhat different from a complete webform submission,
  // we allow to bypass access check. Moreover, draft here is enforced to be
  // authored by the $account user. Thus we hardly open any security breach
  // here.
  $query
    ->accessCheck(FALSE);
  $this
    ->addQueryConditions($query, $webform, $source_entity, $account, $options);

  // Only load the most recent draft.
  $query
    ->sort('sid', 'DESC');
  return ($sids = $query
    ->execute()) ? $this
    ->load(reset($sids)) : NULL;
}