Problem/Motivation
\Drupal\Core\Entity\EntityStorageBase::doPreSave does not reload the 'original' node into $entity->original when workflows are enabled for the bundle and the entity being updated is not the 'Default Revision'.
Steps to reproduce
- Enable the Workflows module
- Add Basic Page as applying to the 'Editorial' workflow
- Create and move a basic page through the workflow to published, then set to draft
- Finally, edit the non-default revision (draft) basic page again and set it to ready for review
- In a presave hook, $entity->original will be set to the published revision instead of the draft revision.
Proposed resolution
\Drupal\Core\Entity\EntityStorageBase::doPreSave uses \Drupal\Core\Entity\EntityStorageBase::loadUnchanged instead of loading by the node's revision ID when the entity is not the default revision.
Workaround
Load the 'original' yourself in hook presave via the entity's revision ID.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | presave-fix-revisions.patch | 985 bytes | makbay |
| #10 | presave_wrong_original-3201209-10.patch | 4.07 KB | kala4ek |
Issue fork drupal-3201209
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 #3
mattsqd commentedComment #6
joachim commentedLooks good, but needs tests.
Comment #9
sachin.bansal27 commentedStill facing this issue in Drupal 9.5.0. Anyway to fix it? Thanks
Comment #10
kala4ekIncreasing the priority of that ticket, because a lot of code do compare entities in the wrong way now.
Also attached the actual changes from MR as patch, so it can be safely used with composer.
Comment #12
makbay commentedThanks for the MR and patch but this is still working incorrectly when the latest saved entity is the default version.
Since the patch is checking if the latest version is default or not, in case the latest revision is default (published), the $entity->original again gets the previous default (published) revision instead of the latest revision.
Steps to reproduce after patch
So, I think we need to remove !$entity->isDefaultRevision() check from the if block.
I'll create another MR for this.
Comment #16
makbay commentedComment #17
tobiasbComment #18
brunoalmeida commentedI tested the #16 patch using the 10.3.7 core version and it's working.
Comment #19
berdirI knew there was another one. This is fixed now in 11.x by #2839195: Add a method to access the original property