We have a Drupal 8 site running Webform 8.x-5.2. We have a special role, "Webform Editor", who is not a developer, but they are trained to create the webforms that we need for our organization.

We've been dealing with some organizational issues about who is getting what webform submission emailed to them. To help us troubleshoot the issue, we the developers want to implement a feature where each webform submission gets automatically copied (cc'ed or sent separately) to an email address that we devs have access to.

I looked at the webform module's hooks, and I didn't see any that jumped out at me as a post-submission hook. Webform version 7.x had one, but version 8.x doesn't appear to.

I made a custom submission handler, but realized I would have to add it manually to all existing webforms (we have more than I want to click through).

I began to write a form_alter hook to add custom submit handler, but when I debugged the $form and $form_state, I didn't see any information (i.e. sid) about the submission record. I suppose that the submit hooks fire before the submission record is created.

In the webform cookbook, there's a recipe for "How can you automatically create a default email handler for a webform when it is created", but again, I want to automatically add this to existing webforms.

If I could do this with something like a hook, once and for all, that is what I'm looking for. If the answer is "No, you can't do what you want automatically; you'll have to make a handler and manually add it to all existing webforms", am I interested in hearing that answer, too. I don't want to chase down any more rabbit holes of approaches that won't work.

  • What's with hook_entity_insert? This hook runs once the entity has been stored.
    – leymannx
    Aug 6, 2019 at 15:05
  • @leymannx I don't know, what's with it? If it will address my problem, would you mind posting an answer?
    – user1359
    Aug 6, 2019 at 15:06
  • I'm mobile right now. Maybe you can try it out and post an answer if it's working?
    – leymannx
    Aug 6, 2019 at 15:07
  • @leymannx I'm digging into it presently. If I get it working, I will post an answer and credit you. Thanks : )
    – user1359
    Aug 6, 2019 at 15:08

1 Answer 1


I am going to go ahead and say No, there isn't any hook or otherwise automated way to do this.

I looked at hook_entity_insert(), as leymaxx suggested. From looking at the Webform Submission entity at /src/Entity/WebformSubmission.php, it appeared to me that the Webform Submission entity is not what triggers the emails and handlers of the webform, but rather the Webform entity does.

Looking further at the Webform entity at /src/Entity/WebformSubmission.php, I found functions for invoking handlers, but these only appeared to loop through existing handlers already attached to the Webform entity. So, there is no way to call an arbitrary handler on a webform.

What I'm going to do is create a custom handler, attach it manually to existing webforms, and use this recipe that I referenced in my question to have it automatically attached to new webforms as they are created.

Edit We are using config_export on our site, which has yamls for all of our current webforms. Because of this, I was able to copy and paste the additional email handler into the yaml, and do a config import, to update existing webforms. This saved some time over manually editing them in the web interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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