1

I am trying from within a hook_webform_submission_presave() programmatically set a webform submission to draft. We are creating an event registration system with webforms and some events require approval. The thought is if an event requires approval we would set submissions to draft and admins could then "approve" them by making them no longer drafts.

Maybe there is a better way to handle this functionality and i'm open to ideas though I am not sure why this cleaned up hook below doesn't set submissions to draft mode.

function lebow_events_webform_submission_presave(WebformSubmissionInterface $webform_submission) {
  $current_data = $webform_submission->getData();
  $current_data['in_draft'] = TRUE;
  $webform_submission->setData($current_data);
}
3

Turns out I need to do this to save draft, the setData is only used to set element data.

$webform_submission->set('in_draft', TRUE);
| improve this answer | |
  • Thanks, I was still using setValue() but that has changed apparently! – baikho Jun 8 at 15:07
0

I tried using $webform_submission->set('in_draft', FALSE); but the results of the webform keeps saying "DRAFT".

this is the conditional where I'm applying this line of code:

if ($response->getStatusCode() == 201 && isset($webform_submission)) {
    $webform_submission->setElementData('state', 2); // state[0]: draft | state[1]: lead enviado | state[2]: enviado a SUR.
    $webform_submission->set('in_draft', FALSE);
    $webform_submission = WebformSubmissionForm::submitWebformSubmission($webform_submission);
}

Thanks

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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