Problem/Motivation

File entities can not be saved in a workspace.

The article gets created but the image field is being skipped. Checking the logs gives
"RuntimeException: This entity can only be saved in the default workspace. in Drupal\workspaces\EntityOperations->entityPresave() (line 128 of /home/d0fao/www/core/modules/workspaces/src/EntityOperations.php)."

Which points to file entity not being able to be created in the non-default workspace since the file entity is not revisionable.
I recall reading about some issues why this was not supported. The problem here lies that this also makes it impossible to create (local) image media entities in the non-default workspace.

I was expecting this to be possible, but seems my expectation was incorrect. Am i doing something wrong here in the usage of workspaces. I was expecting it to be possible to create entities with file fields in the stage workspace, and 'publish' them to live when everything was done.

Steps to reproduce

  • Install standard profile
  • Enable workspaces
  • Switch to staging workspace
  • Create article with image attached

Proposed resolution

Use IgnoredWorkspaceHandler for the file entity type.

Remaining tasks

Review.

User interface changes

Nope.

API changes

Allow CRUD operations for files in a workspace.

Data model changes

Nope.

Release notes snippet

Nope.

Issue fork drupal-3025785

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

mallezie created an issue. See original summary.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mattshoaf’s picture

Agree, functionality is very incomplete without being able to manage images/files.

mallezie’s picture

Status: Active » Needs review
StatusFileSize
new2.99 KB

Attached patch allows to implement a method to allow this based on entity types.

Adds a method to the workspace manager, and the interface.

In an custom workspace manager you can then implement this function per entity type is needed.

This is a different solution then the one in #3101671: Add mechanism to have workspaces skip processing entity types Although the issue / problem is the same.

Credits to mheip for the patch.

mallezie’s picture

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

melodia40943’s picture

Status: Needs review » Needs work

Patch test: 2998414-allow-non-revisionable-entities-6.patch
I tested the patch on a drupal 9.2.0 under php 7.3 without any noticeable improvement. I still can't add photos anywhere other than the default workspace.
I have looked in the configurations and in the permissions without finding anything to solve the media problem.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dspachos’s picture

I can confirm @Melodia40943, seems that in Drupal 9.3.x and PHP 7.3 doesn't make any difference.

Fyi, for me this https://www.drupal.org/project/drupal/issues/3101671 worked fine.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

s_leu’s picture

s_leu’s picture

I'm not sure if the proposed solution here actually makes sense. There is already an existing solution to enable/support entity types in, which are not publishable and revisionable, in workspaces by marking them as internal, see #3027598: Omit workspaces entity presave and predelete hooks for internal entities.

Given that possibility It feels relatively cumbersome to override the workspace manager just to allow some entity type to be handled inside workspaces, when compared to implementing hook_entity_type_alter() and marking an existing entity type as internal in a custom module, or even marking a custom entity type as internal right via the internal flag of the entity type annotation. IMO this feels much lighter than overriding a core service to support an entity type, so I'd personally close this as a won't fix. The same goes for #3101671: Add mechanism to have workspaces skip processing entity types.

Regarding comments #10 and #13: Using the patch posted in #6 isn't enough to make this work, as the author of the patch wrote in #5 :

In an custom workspace manager you can then implement this function per entity type is needed.

In fact to implement a custom workspace manager will become essential in order for the patch to do anything.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

amateescu’s picture

Status: Needs work » Needs review
Parent issue: » #2732071: WI: Workspace module roadmap

Now that #3101671: Add mechanism to have workspaces skip processing entity types is done, we can support CRUD operations for files in a workspace :)

amateescu’s picture

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs Review Queue Initiative

Wonder if the issue summary could be updated? I added the standard template but some sections I can't speak on.

Left some nitpicky stuff on the MR.

Test-only has already been ran here https://git.drupalcode.org/issue/drupal-3025785/-/jobs/982598 so test coverage is there.

Thanks!

amateescu’s picture

Title: Cannot create entity with image in non-default workspace » Cannot create entity with image in a workspace
Priority: Normal » Major
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update +WI critical

Fixed all comments from the MR and updated the issue summary. Thanks for reviewing :)

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

amateescu’s picture

Status: Needs work » Needs review

Rebased on top of latest 11.x.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback has been addressed and summary is clear. Thanks!

  • catch committed 36465e60 on 10.3.x
    Issue #3025785 by amateescu, mallezie, s_leu, smustgrave, tim.plunkett:...

  • catch committed 4229a611 on 11.x
    Issue #3025785 by amateescu, mallezie, s_leu, smustgrave, tim.plunkett:...
catch’s picture

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

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

Status: Fixed » Closed (fixed)

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