Using the webform API in a custom controller, I need to save a draft with another webform_submission as its source entity.

However the current code seems to be designed with the assumption that a draft cannot have a webform_submission as a source entity.

As seen in WebformSubmissionForm::setEntity():

    $this->sourceEntity = $this->requestHandler->getCurrentSourceEntity(['webform', 'webform_submission']);

if I remove webform_submission as a filter I'm able to load a draft.

I can understand why it is filtering the webform entity but is there a reason why this code is filtering for webform_submission?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ptsimard created an issue. See original summary.

ptsimard’s picture

Here is a patch that fixes the issue for me. Hopefully this passes all the tests?

ptsimard’s picture

Status: Active » Needs review
jrockowitz’s picture

Originally, I was trying to avoid having a webform or submission become the source entity.

I think the source entity filtering needs to be reworked. I might need make it possible to set the available source entities as an advance setting.

For example in #2853870: Limit User Per Entity Submission: Does not work when Webform is Attached to a Submission, the webform submission needs to be source entity, instead of the attached webform node.

Status: Needs review » Needs work

The last submitted patch, 2: draft_filter_webform_submission-2854714-2.patch, failed testing.

jrockowitz’s picture

I am vacation for the rest of the week but I am going to add some notes here.

Tasks

  • Add 'excluded_source_entities' to webform settings.
  • Default 'excluded_source_entities' should be 'webform' and 'webform_submission'.
  • Update WebformSubmission::preCreate and WebformSubmissionForm::setEntity to use 'exclude_source_entities'.
  • Update tests.
  • Write tests for excluded source entities.

@ptsimard if your patch works for your setup, you should be okay using it, until I get fully working and integrated solution.

jrockowitz’s picture

I think this might be opportunity to move all source entity related webform settings into a dedicated details element which could include more documentation.

  • jrockowitz committed f3f9f9a on 2854714-source-entity
    Issue #2854714 by ptsimard: Draft with webform_submission as source...

  • jrockowitz committed 0857b85 on 2854714-source-entity
    Issue #2854714 by ptsimard: Draft with webform_submission as source...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
2.67 KB

Status: Needs review » Needs work

The last submitted patch, 10: draft_with-2854714-10.patch, failed testing.

  • jrockowitz committed 521d167 on 2854714-source-entity
    Issue #2854714 by ptsimard, jrockowitz: Draft with webform_submission as...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
2.74 KB

Status: Needs review » Needs work

The last submitted patch, 13: draft_with-2854714-13.patch, failed testing.

  • jrockowitz committed dad5aa0 on 2854714-source-entity
    Issue #2854714 by jrockowitz, ptsimard: Draft with webform_submission as...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
3.15 KB

  • jrockowitz committed 737a24d on 8.x-5.x
    Issue #2854714 by jrockowitz, ptsimard: Draft with webform_submission as...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download and review the latest dev release.

ptsimard’s picture

Seems to be working for me thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.