1

How to fetch all the webform drafts saved based on user id?

I tried the below query and it gives me all submission id's but how do I get just the drafts

$query = \Drupal::entityQuery('webform_submission')
      ->condition('uid', 123)
      ->condition('webform_id','test_1');

1 Answer 1

4

You could try this:

$query = \Drupal::entityQuery('webform_submission')
  ->condition('uid', 123)
  ->condition('webform_id, 'test_1')
  ->condition('in_draft', TRUE);

$entity_ids = $query->execute();

Or via the EntityTypeManager:

/** @var \Drupal\webform\WebformSubmissionInterface[] $submissions */
$submissions = \Drupal::entityTypeManager()
  ->getStorage('webform_submission')
  ->loadByProperties([
    'uuid' => 123,
    'webform_id' => 'test_1',
    'in_draft' => TRUE,
  ]);
1
  • I would recommend to use entityQuery, it's more readable and loadByProperties by property may be deprecated in the future.
    – gagarine
    Commented Aug 9, 2022 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.