Reason
Due to some requirements I need to have multiple webform_submission drafts stored per user. This way, a user can jump from one draft to another at different points in time.
Problem
Upon loading a webform draft, loadDraft() resets the query results array to the first item as seen here:
return $this->load(reset($entity_ids));
Solution
I need to be able to pass in a condition, for example a sid or a token to the loadDraft() query so it returns the correct draft.
My approach was to add a 'draft_conditions' webform setting defined as a associative array of conditions (simple equivalence conditions) and iterate on these in the loadDraft function.
Maybe there is a better way to do this but it satisfies my use case.
Thoughts, suggestions?
Patch incoming.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | allow_multiple_drafts-2856472-13.patch | 128.26 KB | jrockowitz |
| #11 | allow_multiple_drafts-2856472-10.patch | 105.04 KB | jrockowitz |
| #8 | allow_multiple_drafts-2856472-8.patch | 104.65 KB | jrockowitz |
| #2 | multiple_drafts_per_user-2856472-2.patch | 723 bytes | ptsimard |
Comments
Comment #2
ptsimard commentedComment #3
jrockowitz commentedI think there is way to get 'view previous submissions' to support 'view previous drafts'.
There would definitely have to be a new setting for 'Allow multiple drafts' (draft_multiple) which would disable the autoloading of the previous draft and link to the multiple previously saved drafts.
This is not a lot of work but not something that is on my immediate roadmap. This feature would definitely require some tests.
Comment #4
jase-alexander commentedWould love to see this implemented for the reporting system I am working on.
Currently I have a check box on each submission to mark a entry as complete and do not allow the user to save as a draft.
Obviously not ideal.
Comment #5
jrockowitz commentedComment #8
jrockowitz commentedThe attached patch adds 'Allow users to save multiple drafts.' to webform settings which permits multiple drafts to be saved, restored, and submitted.
The patch still needs some test coverage.
Comment #11
jrockowitz commentedComment #13
jrockowitz commentedComment #16
jrockowitz commentedI committed the patch. Please download the latest dev release to review.
Comment #18
jmunger commentedAre there any plans to get this working in Drupal 7?
Comment #19
jrockowitz commentedProbably not but you can create new issue for Drupal 7.