You are here

public function YamlFormSubmissionStorage::loadDraft in YAML Form 8

Get form submission draft.

Parameters

\Drupal\yamlform\YamlFormInterface|null $yamlform: A form.

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

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

Return value

\Drupal\yamlform\YamlFormSubmissionInterface A form submission.

Overrides YamlFormSubmissionStorageInterface::loadDraft

File

src/YamlFormSubmissionStorage.php, line 49

Class

YamlFormSubmissionStorage
Defines the form submission storage.

Namespace

Drupal\yamlform

Code

public function loadDraft(YamlFormInterface $yamlform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
  $query = $this
    ->getQuery();
  $query
    ->condition('in_draft', TRUE);
  $query
    ->condition('yamlform_id', $yamlform
    ->id());
  $query
    ->condition('uid', $account
    ->id());
  if ($source_entity) {
    $query
      ->condition('entity_type', $source_entity
      ->getEntityTypeId());
    $query
      ->condition('entity_id', $source_entity
      ->id());
  }
  else {
    $query
      ->notExists('entity_type');
    $query
      ->notExists('entity_id');
  }
  if ($entity_ids = $query
    ->execute()) {
    return $this
      ->load(reset($entity_ids));
  }
  else {
    return NULL;
  }
}