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.
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 3025785-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-3025785
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:
- 3025785-support-files-in-workspaces
changes, plain diff MR !6905
Comments
Comment #4
mattshoafAgree, functionality is very incomplete without being able to manage images/files.
Comment #5
mallezieAttached 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.
Comment #6
mallezieRerolled patch.
This is also somewhat related with #3027598: Omit workspaces entity presave and predelete hooks for internal entities
Comment #10
melodia40943 commentedPatch 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.
Comment #13
dspachos commentedI 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.
Comment #15
s_leu commentedComment #16
s_leu commentedI'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 fact to implement a custom workspace manager will become essential in order for the patch to do anything.
Comment #21
amateescu commentedNow that #3101671: Add mechanism to have workspaces skip processing entity types is done, we can support CRUD operations for files in a workspace :)
Comment #22
amateescu commentedComment #23
smustgrave commentedWonder 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!
Comment #24
amateescu commentedFixed all comments from the MR and updated the issue summary. Thanks for reviewing :)
Comment #25
needs-review-queue-bot commentedThe 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.
Comment #26
amateescu commentedRebased on top of latest 11.x.
Comment #27
smustgrave commentedFeedback has been addressed and summary is clear. Thanks!
Comment #30
catchCommitted/pushed to 11.x and cherry-picked to 10.3.x, thanks!