Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have a custom webform handler that works great to set email recipients to specific values based on how the webform is filled out.
In addition to setting the recipients, I need to save some values into a hidden field for later use, when the form submission is displayed in a View using the webform_views module.
I have tried:
$webform_submission->setElementData('county',$county->getTitle());
$webform_submission->setElementData('division', $division_code);
$webform_submission->save();
which gives an error on save.
and:
// Get submission data.
$data = $webform_submission->getData();
// Change submission data.
$data['county'] = $county->getTitle();
$data['division'] = $division_code;
// Set submission data.
$webform_submission->setData($data);
// Save submission.
$webform_submission->save();
which gives the error:
Maximum function nesting level of '256' reached, aborting!
Any ideas on how to change/save submission values in the sendMessage method?
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI am guessing that you are calling
$webform_submission->save();
via hook_entity_save() which is triggering the recursion.You can use the \Drupal\webform\Entity\WebformSubmission::resave to update and save the submission data without triggering any save related hook.
So the exact tweak is to change
$webform_submission->save();
to$webform_submission->resave();
.Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented