Problem/Motivation
Getting below error on creating node inside the Group Node on Drupal 10.4.x-dev.
The website encountered an unexpected error. Try again later.
Drupal\Core\Entity\EntityStorageException: This entity can only be saved in the default workspace. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
workspaces_entity_presave()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 217)Steps to reproduce
1. Install and enable the following modules: Group, Group Node
2. Create the Group type and Enable content type Article on Content(Entities that can be added to this group type).
3. Keep uncheck for Use 2-step wizard when creating a new Content
3. Switch to Stage (or any other) workspace.
4. Goto the group/GROUP_ID/nodes and goto node add /group/GROUP_ID/content/create/group_node/article
5. On saving you can able to see the error.
6. Node created successfully but not added to the Group.

Proposed resolution
The Workspaces support the core content node entity but Workspaces do not support the Group entity.
Due to that, a node was created but not attached to the Group.
Need to create fix to solve the issue.
Remaining tasks
Exception handling.
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | After-fix-node-save-3469890.png | 390.55 KB | vinmayiswamy |
| #13 | After-fix-3469890.png | 353.95 KB | vinmayiswamy |
| #13 | Before-fix-WSOD-3469890.png | 634.12 KB | vinmayiswamy |
| Group-node-type-Recommended.png | 238.04 KB | arunkumark | |
| Group-node-type-default.png | 243.43 KB | arunkumark |
Issue fork group-3469890
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 #2
arunkumarkComment #3
arunkumarkTemporary Solution:
If you are keeping Use 2-step wizard when creating a new Content entity within a group the page won't break but it will not be allowed to the Group.
Comment #4
cilefen commentedThis issue is perhaps for the Group module rather than for Drupal Core.
Comment #5
arunkumark@cilefen
Yes, the form Workspace support need to done from Group. But, page break should not happen. We have to handle the exception and solving the page break.
Comment #6
amateescu commentedThrowing this exception is very much intentional, we need to warn developers that there's something to fix.
Comment #7
arunkumarkIt was better to show an error in validation or show message rather than showing the page break.
Comment #8
heddnFor now, in a custom module I'm going to remove the group.module's submit handler and use one that utilizes a cron queue instead.
Comment #9
heddnOK, that won't work. Instead I dove into seeing if we could actually support it. It would natively support it if relationships were revisionable. Since they aren't, see #3161130: Support for Revisions of Group Relationship Entities, I think we should just mark the relationship entity as ignored. Working on MR.
Comment #10
heddnHere's a fairly minimal solution. Which should work in most cases.
Comment #12
heddnFeedback on MR addressed
Comment #13
vinmayiswamy commentedHi, I have tested the fix provided in MR !177. I followed the steps outlined in the issue summary to reproduce the issue before applying the fix and to verify the solution afterward.
Before the fix, I encountered the White Screen of Death (WSOD) with the following error message:
Drupal\Core\Entity\EntityStorageException: This entity can only be saved in the default workspace. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).Although the node was created, it wasn’t added to the group, and the WSOD appeared with the above error logged.
After applying the fix, the issue was resolved. The WSOD no longer occurred, and the node was successfully created and added to the group within the non-default workspace.
Node added to group

Node creation

Attaching before and after screenshots for reference.
I believe this is now good to go for RTBC!
Thanks!
Comment #14
heddnBased on #13, marking RTBC.
Comment #15
tvalimaa commentedHi, i can create empty groups and group content with this patch but how about users? The group creator automatically becomes a member and adding member after group if created gives
This entity can only be saved in the default workspace.. Is that related group module or overall user workspaces?Comment #16
jwilson3RTBC++ Would love to see this one-liner in both the 3.x and 2.x branches.
The base use case here is to have group members / content editors add *content* to groups in non-live Workspaces, which works great with MR 177. Therefore, comment #15 should be moved to a follow-up. Adding members to groups in a non-live Workspace seems like a corner case. I wonder if core user creation in non-live Workspaces even works as expected?
Comment #18
amateescu commentedDiscussed this issue with Kristiaan at Dev Days Athens, and we agreed that it looks good. Opened a 4.0.x MR so it can be fixed everywhere.
Comment #22
kristiaanvandeneyndeThanks everyone!