Spawn Maestro Workflow is triggered when saving a draft webform

Created on 18 August 2023, over 1 year ago
Updated 22 August 2023, over 1 year ago

Problem/Motivation

Steps to reproduce

  • Create a Webform and a Workflow
  • In Webform Settings > Submissions > Submission draft settings, allow users to save drafts
  • In Webform Settings > Emails / Handlers, add the Spawn Maestro Workflow handler
  • Start filling in the webform and click Save Draft

The workflow is started, which I would not expect to happen until the form is submitted.

Proposed resolution

In MaestroWebformHandler::postSave(), don't start the workflow if $webform_submission->getState() === WebformSubmissionInterface::STATE_DRAFT_CREATED or WebformSubmissionInterface::STATE_DRAFT_UPDATED.

Alternatively, do something like Drupal\webform\Plugin\WebformHandler\EmailWebformHandler - the Advanced tab has checkboxes to choose which webform states trigger the handler. This would be more complex but more flexible.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mi-dave
    • _randy committed 2fba4af2 on 3.x
      Issue #3381908: Spawn Maestro Workflow is triggered when saving a draft...
  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada _randy

    Give the patch I just posted a try. Opens up a checkbox for a handful of options on webform submission statuses. This should help.

  • Status changed to Needs work over 1 year ago
  • Wow, thanks for the quick turnaround!

    Unfortunately it seems $update = TRUE when submitting a draft, since the record already exists in the database. But I think that check is no longer needed, since the state will be WebformSubmissionInterface::STATE_UPDATED when updating an existing record.

    Also, I think the default value '' should be [WebformSubmissionInterface::STATE_COMPLETED] - otherwise array_search() triggers a TypeError, and the handler not run by default.

    Thanks!

  • 🇨🇦Canada _randy

    I had a stubbed out implementation of this handy, so able to quickly turn it around!

    I have a second commit that fixed the type array issue already.

    I'll take a look at the webform status, bit for now, this should probably do the trick.

    • _randy committed c24d9928 on 3.x
      Issue #3381908 by _randy: Spawn Maestro Workflow is triggered when...
  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada _randy

    Dev release now has all updates to support this change for those who have not configured their handlers with the status selectors as well as for those using webform draft states that don't use custom Maestro handlers in place.

  • Great, thanks. Looks good, but I will test it properly on Monday and confirm.

  • Status changed to RTBC over 1 year ago
  • LGTM - thanks again. :-)

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024