Problem/Motivation
All revisions created in a workspace are marked as new revisions in an entity presave hook (\Drupal\workspaces\Hook\EntityOperations::entityPresave), but that hook is invoked by the entity storage after invoking the ::preSave() method on the entity's fields.
This is problematic for field types that have some logic based on the fact that we're about to save a new revisions, like Entity Reference Revisions: https://git.drupalcode.org/project/entity_reference_revisions/-/blob/8.x...
Steps to reproduce
On a Drupal 11.2 site with Workspaces and Paragraphs enabled, trying to create a new entity that references paragraphs will bump into the exception introduce in #3499181: Disallow saving the current default revision as a non-default revision.
Proposed resolution
Ensure that we mark the second revision created by Workspaces for newly-created entities as a new revision in \Drupal\workspaces\Hook\EntityOperations::entityInsert().
Remaining tasks
Review.
User interface changes
Nope.
Introduced terminology
N/A
API changes
Nope.
Data model changes
Nope.
Release notes snippet
N/A
Issue fork drupal-3546740
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
amateescu commentedComment #4
alecsmrekar commentedWorks well, thanks!
Comment #5
plach+1 :)
Comment #6
divyat commentedThe patch worked for me too.
Thanks.
Comment #8
dcam commentedWorkspaceEntityOperationsTestis failing.Comment #9
amateescu commentedFixed.
Comment #10
catchThis is leaving the ::setNewRevision() in ::entityPresave(). I think we either need to remove it, or add a comment to explain why we call it twice in two different hooks now.
Comment #11
amateescu commentedAdded a comment to explain why we also need to it here. This new
::setNewRevision()call is needed for the specific case of adding a new published entity in a workspace.Comment #14
catchCommitted/pushed to 11.x and cherry-picked to 11.2.x, thanks!
Comment #19
amateescu commentedOpened a new MR to fix the 11.2.x failing test.
Comment #21
catchWent ahead and committed the backport follow-up to get 11.2.x back to green.