Based on a slack discussion with @amateescu and @plach:
Problem/Motivation
From: https://www.drupal.org/project/drupal/issues/3023194
As mentioned above, each revision has contextual metadata attached, allowing to look up the fittest revision for the specified context. In fact, a revision matching exactly the specified context might not exist, so a fallback logic needs to be available. The context hierarchy defined through weights is used to support that: more and more generic fallback contexts are built until a suitable revision is found. For instance, the following situation may happen:
Current context: [ws: stage, lang: it, user: 4] Fittest revision: [ws: stage, lang: it]
To be able to select the "active" or "fittest" revision for the current context, the revision has to store the related context values in an accessible and queryable manner.
Proposed resolution
A solution proposed by @amateescu: Revision negotiation relies on entity or revision fields. Every context provider defines the field name that is used to determine a revisions "fitness" :D
For example:
Current context: [ws: stage, lang: it, user: 4]
Fittest revision: [ws: stage, lang: it]
The language context would use the existing langcode field. The user context the revision_id field and the workspace context would rely on a workspace field (follow up ticket). This would result in SQL conditions that can be used to order revisions:
select revision_id, (langcode = 'en') * 2 + (revision_uid = '1') * 1 + (workspace != 'stage') * -1 as fitness from node_revision where nid = 1 order by fitness desc ;
This example would prioritize revisions in the current language and then by the current user but deprioritize any revision that is not in the current workspace.
Remaining tasks
- Add an extension point for context providers to define entity field names.
- Provide a configuration schema and page for managing context and weights.
- Extend the `getActive` implementation in https://www.drupal.org/project/drupal/issues/2942907#comment-12910929 to take context fitness into account.
- Refactor the workspaces module to use a field instead of the workspace_associations entity. (follow up issue)
- Provide an upgrade path for the workspace module. (follow up issue)
Comments
Comment #2
pmelab commented