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

captaindav created an issue. See original summary.

jrockowitz’s picture

Status: Active » Needs review

I 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();.

jrockowitz’s picture

Status: Needs review » Closed (works as designed)