Problem/Motivation

webformautosave_webform_submission_form_alter() saves a new submission as a draft while the form is being built (webformautosave.module:91-95). It does this whenever autosave is enabled, drafts are enabled, and purge is set to draft or all.

Saving an entity inside a form alter means a GET request writes data:

  • Every view of a new form creates a submission, including page prefetches, refreshes, abandoned visits and bots that can reach the form.
  • Every handler's preSave() / postSave() and every hook_webform_submission_insert() runs during the GET, so sites with side effects on save (status tracking, notifications, logs) trigger them just by opening the form.
  • The condition depends on the purge setting, which is a different concern from whether a draft should be created early.

Proposed resolution

  • Create the draft lazily, on the first autosave or the first Next / Save draft submit. Webform already saves drafts at those points when draft_auto_save is on.
  • If an early sid is really needed (for example, for optimistic locking or the autosave button), make early creation an explicit per-webform setting that defaults to off, and don't tie it to the purge setting.

Remaining tasks

  • Confirm which features depend on the submission having an ID at first render (the autosave trigger and optimistic locking are only added when $webform_submission->id() is set).
  • Write the MR and tests.

User interface changes

Possibly a new per-webform setting, if early creation is kept as an option.

API changes

None.

Data model changes

None. Fewer empty draft submissions get created.

Comments

rymcveigh created an issue.