3

I am trying to save a webform submission inside the postSave in a CustomWebformHandler class.

class CustomWebformHandler extends WebformHandlerBase {
[..]
     public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
        $data = $webform_submission->getData();
        $data['ssa_attachment'] = $doc_id; //doc_id is retrieved with a query
        $webform_submission->setData($data);
        $webform_submission->set('in_draft', TRUE);
        $webform_submission->save();
     }
}

I get the following exception.

Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "Entity validation was skipped."

I tried to validate before saving and I get this exception.

Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction: SELECT w.next_serial AS next_serial\nFROM\n{webform} w\nWHERE webform_id = :db_condition_placeholder_0 FOR UPDATE;

How can I trigger the validation before saving?

  • "I am trying to save a webform submission inside the postSave ..." - regardless of validation, I don't know if this is even the question you want to be answered, you can't save the same entity in an postSave event, this causes all kind of errors because you invoke the same event again. – 4k4 Nov 14 at 13:27
  • @Jdrupal, yes, postSave() is for things like invalidating cache tags or you can even modify other entities, but you shouldn't save the same entity again $webform_submission->save(), which leads to a stack overflow if no other random error occurs first. – 4k4 Nov 14 at 13:41
3

The WebformSubmission::resave() method prevents the ::save and ::postSave recursion issue from occuring.

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.