Content Staging with Workspaces and Entity Reference
A large organization uses Drupal 10 with the Workspaces module to stage content changes. They have a workspace called 'Staging' where editors make changes to articles and related media. The site has 5,000 articles and 2,000 media items. Editors report that when they add a new media item in the Staging workspace and reference it from an article in the same workspace, the media item appears in the default workspace as well, even before publishing the workspace. Additionally, when they publish the workspace, some articles that were not changed in the workspace are also published with old revisions. The team wants to ensure that media items created in a workspace are not visible in the live site until the workspace is published, and that only changed content is published.
1. Why are media items created in the Staging workspace visible in the default workspace before publishing?
Read the worked answer
In Drupal's Workspaces module, content entities are workspace-specific, but media items are content entities and should be isolated to the workspace. However, if the media item is referenced by an article that is in the default workspace, the media item may be visible because the reference is resolved in the default workspace. But if the article is also in the Staging workspace, the media should not be visible in default. The issue may be that the media item was created in the Staging workspace but the file entity is not workspace-aware. Files are not content entities and are not workspace-specific. When a media item is created, the file is saved in the default file system and is accessible via its URL regardless of workspace. So even if the media entity is in Staging, the file URL is public. To prevent this, the team can use the 'Workspaces' module's 'File' support, but it's limited. A workaround is to use a private file system or to use the 'Content Moderation' module to keep media unpublished until the workspace is published. Alternatively, they can use the 'Workspace' module's 'Live' workspace and ensure that media items are not published until the workspace is published. But the core issue is that files are not workspace-aware. The team should consider using the 'Workspaces' module with the 'File' module's workspace support if available, or use a custom solution to restrict file access.
2. Why are unchanged articles published with old revisions when the workspace is published?
Read the worked answer
When a workspace is published, all content that has a revision in the workspace is published. If an article was not changed in the workspace, it should not have a new revision in the workspace, so it should not be affected. However, if the article was modified in the workspace (even if reverted), it may have a revision. Another possibility is that the workspace publishing process publishes all content that is in the workspace, including those that were not explicitly changed but were perhaps edited and saved without changes. To ensure only changed content is published, the team should review the workspace's content before publishing. They can use the 'Workspace' module's 'Diff' feature to see changes. Also, ensure that editors are not saving articles unnecessarily. If the issue persists, check if there are pending revisions in the workspace for those articles. The 'Workspaces' module publishes all revisions that are in the workspace. So if an article has a revision in the workspace, it will be published. To avoid this, editors should only edit articles that need changes. Additionally, the team can use the 'Content Moderation' module with workspaces to have more control, but it's complex.
3. What configuration or module changes would you recommend to achieve the team's goals?
Read the worked answer
To isolate media items until workspace publication, the team can use the 'Workspaces' module with the 'Media' module's workspace support. Drupal core's Workspaces module supports content entities, including media. However, the file issue remains. They can use the 'Private File System' and configure media types to use private files, so that files are not publicly accessible until the media entity is published. But private files require a download method and may not be suitable for all media. Alternatively, they can use the 'Content Moderation' module to keep media unpublished until the workspace is published, but that requires media to be moderated. For the publishing of unchanged articles, the team should ensure that only changed content is in the workspace. They can use the 'Workspace' module's 'Publish' operation which publishes all content in the workspace. To have more granular control, they can use the 'Content Moderation' module with workspaces, where each content item has a moderation state. Then, publishing the workspace would publish only those in a published state. But this requires configuration. A simpler approach is to use the 'Workspaces' module's 'Replicate' feature to create a workspace with only the changes. The team should also consider using the 'Entity Reference Revisions' module for media references to ensure that the correct revision is referenced.