I'm trying create/update Webform Submission programmatically. I already know how the create new submission by following the Drupal 8 API. Now I'm trying to build a update method, I refer to the Webform module source-code and API documents but couldn't find a solution. I guess they remove webform_get_submission
webform_submission_update
functions in Drupal 8.3 as-well.
$values = [
'webform_id' => 'attendees_info',
'in_draft' => FALSE,
'uid' => $uid,
'langcode' => 'en',
'token' => 'at_'.$token,
'uri' => '/webform/attendees/api',
'remote_addr' => '',
'data' => [
'name' => $name,
'email' => $email,
'gallery_url' => 'gallery/'.$token,
],
];
$webform = Webform::load($values['webform_id']);
$is_open = WebformSubmissionForm::isOpen($webform);
if ($is_open === TRUE) {
// Validate submission.
$errors = WebformSubmissionForm::validateValues($values);
// Check there are no validation errors.
if (!empty($errors)) {
return $errors;
}
else {
// Submit values and get submission ID.
$webform_submission = WebformSubmissionForm::submitValues($values);
return $webform_submission->id();
}
}
Above is my Submission creation code, I don't know how to do the update method. Is anyone face this issue before? Hope someone will help me on this, thanks.