Problem/Motivation
Currently our custom form validation routine checks whether the entity is new, and if so simply skips any further validation. This means that even if the original author of the node pushes it into a state they shouldn't (past the initial state), we don't catch it, and happily save it. This breaks the logic of the module in Edit cases, and just punts on figuring out the logic.
Steps to reproduce
- Install this module and set it up per normal
- Create a new node with a workflow
- Set the workflow state to some later state (past the initial one)
- Save as Draft
- Observe no error that "you can't update workflow state if you're saving as draft" per usual
- Node is created with incorrect initial state
Proposed resolution
Incorporate some better checking when the entity is new. Workflow can tell us what the "first state" for a workflow/entity/user is, so we can check whether the current state matches that. If not, we should throw the usual error.
Remaining tasks
Roll a patch to test the fix in situ
Extend tests to cover this case
User interface changes
Module should throw the usual error if you try to change workflow state when creating a new node and saving as draft.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3506827-detect-first-workflow-state-if-entity-isnew-2.patch | 4.39 KB | spiderman |
Issue fork workflow_save_as_draft-3506827
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
spidermanComment #3
spidermanIn testing this on our project, I realized that the patch fixed some logic that was duplicated elsewhere in the module. We check whether the workflow state has changed in the case where "Update workflow" is pressed so we can validate it *has* changed, but also when "Save as Draft" is pressed so we can validate is *hasn't* changed. I've refactored the patch to deduplicate the "has it changed" logic and just set the error appropriately in the 2 different places we're checking.
Comment #5
spidermanThis patch has been operational for a few weeks now. I'm going to commit and cut another beta release to test against.