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

Command icon 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

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
alecsmrekar’s picture

Status: Needs review » Reviewed & tested by the community

Works well, thanks!

plach’s picture

+1 :)

divyat’s picture

The patch worked for me too.
Thanks.

dcam made their first commit to this issue’s fork.

dcam’s picture

Status: Reviewed & tested by the community » Needs work

WorkspaceEntityOperationsTest is failing.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Fixed.

catch’s picture

Status: Reviewed & tested by the community » Needs work

This 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.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Added 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.

  • catch committed e9a47ab0 on 11.x
    Issue #3546740 by amateescu, dcam: Initial workspace-published revisions...

  • catch committed 9efb68a7 on 11.2.x
    Issue #3546740 by amateescu, dcam: Initial workspace-published revisions...
catch’s picture

Version: 11.x-dev » 11.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.2.x, thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • catch committed 611798e4 on 11.2.x
    Issue #3546740: update the phpstan baseline.
    

amateescu’s picture

Status: Fixed » Patch (to be ported)

Opened a new MR to fix the 11.2.x failing test.

  • catch committed d31ff79c on 11.2.x
    Issue #3546740 by amateescu, dcam, catch: Initial workspace-published...
catch’s picture

Status: Patch (to be ported) » Fixed

Went ahead and committed the backport follow-up to get 11.2.x back to green.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.