Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
When a module adds additional submit functions to a node submit, and the module's alter hook run's after this module's alter hook, it might happen that some submit functions won't run on submit, which might cause data loss.
There are two ways to solve it: do it with a reference, or use a submit handler on the draft button which calls all submit hooks. I think the second one is better, because it allows other modules to do submit hooks on just the draft saving.
Patch attached for the second solution.
Comment | File | Size | Author |
---|---|---|---|
#2 | save-as-draft-submit-handler-1446730-2.patch | 971 bytes | David_Rothstein |
save_as_draft.patch | 956 bytes | tamasd |
Comments
Comment #1
David_Rothstein CreditAttribution: David_Rothstein commentedThis will cause "Call-time pass-by-reference has been deprecated" notices. But otherwise, the patch looks good and worked fine when I tested it.
Comment #2
David_Rothstein CreditAttribution: David_Rothstein commentedRerolled to remove the "&".
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commentedComment #4
nedjoThis is indeed a bug. Another approach that could be used to address it would be to set save_draft to be the last module invoked in
hook_form_node_form_alter()
via hook_module_implements_alter() so that all other submit handlers have already been added.But rather than messing with hook ordering the current patch looks like the better approach and is ready to go.
Comment #5
askibinski CreditAttribution: askibinski commentedon a side note, here is how publish_button does this: ( similar module by nodeone)
http://drupalcode.org/project/publish_button.git/blob/bae35e4caf57c3dfa3...
Comment #6
NancyDruHas anyone thought about using
array_unshift()
to stick the draft submit before the node submit handler?Comment #7
David_Rothstein CreditAttribution: David_Rothstein commented@NancyDru: Which form element are you referring to, that the array_unshift() would be performed on?
The standard node submit button provided by Drupal core has its own (button-level) submit handlers. This module adds a new button, and that button needs to trigger the exact same thing. So it would seem to need submit handlers of its own in order to do that.
Comment #8
NancyDruI haven't looked specifically at this code, but in several modules that I've written, I had to replace the standard
$form['buttons']['submit']['#submit'][] = 'mymodule_submit';
witharray_unshift($form['buttons']['submit']['#submit'], 'mymodule_submit')
to force my handler to run before Node's.Comment #9
David_Rothstein CreditAttribution: David_Rothstein commentedGot it. Yeah, I've done a lot of that too, but in this case I don't think it will help, since we are constructing a totally new button and adding handlers to that.
Comment #10
deanflory CreditAttribution: deanflory commentedWhen applied to 7.x-1.4:
patch < save-as-draft-submit-handler-1446730-2.patch
patching file save_draft.module
Hunk #1 FAILED at 54.
Hunk #2 succeeded at 70 (offset -11 lines).
1 out of 2 hunks FAILED -- saving rejects to file save_draft.module.rej
When the latest individual file commits are copied over 7.x-1.4 since there is no dev version available on the project page:
save_draft.js
save_draft.module
save_draft.test
patch < save-as-draft-submit-handler-1446730-2.patch
patching file save_draft.module
Hunk #1 FAILED at 54.
Hunk #2 FAILED at 81.
2 out of 2 hunks FAILED -- saving rejects to file save_draft.module.rej
So, 1 out of 3 patches work. I'm thinking this project is dead.
Comment #11
MrHaroldA CreditAttribution: MrHaroldA commented@deanflory: if you clone the git repository, the patch will apply.
Comment #12
rooby CreditAttribution: rooby commentedThanks for the patch and your patience.
This has been committed.
re comment #5, that solution is not ideal and would not help fix this issue.
Comment #13
rooby CreditAttribution: rooby commentedOh, I changed the name of the submit function as I felt nervous about save_draft_submit not being specific enough and risking hook collisions.
Comment #14
rooby CreditAttribution: rooby commentedDrupal 6 could use this too.
Comment #15
rooby CreditAttribution: rooby commentedSince D6 is done now, setting back to D7 and marking fixed.