Workspace negotiators shouldn't be responsible for loading the negotiated workspace entity

Created on 26 April 2024, 6 months ago
Updated 29 May 2024, 5 months ago

Problem/Motivation

Workspace negotiators are currently required to ensure that the negotiated workspace actually exists, and that's problematic for a few reasons:

  • modules that want to vary entire cache bins by a (negotiated) workspace ID can't do that because it happens super early in the request where an entity can't be loaded yet
  • modules can't easily add additional requirements for validating a negotiated workspace, e.g. for implementing the notion of open/closed workspaces

Proposed resolution

In Drupal 10.3 add a new negotiation interface, with a single method: \Drupal\workspaces\Negotiator\WorkspaceIdNegotiatorInterface::getActiveWorkspaceId(), and trigger a deprecation from WorkspaceManager::getActiveWorkspace() for negotiators that don't implement it. Also, move the responsibility for ensuring that the negotiated actually exists to WorkspaceManager::getActiveWorkspace().

In Drupal 11 deprecate the newly introduced WorkspaceIdNegotiatorInterface, and remove it in Drupal 12.

This ensures that every negotiator will be prompted to implement the new method in Drupal 10.3 and 11, then we can safely add ::getActiveWorkspaceId() to the main interface \Drupal\workspaces\Negotiator\WorkspaceNegotiatorInterface.

An additional benefit of this change is that workspace negotiation will be more similar to language negotiation:

  • WorkspaceIdNegotiatorInterface::getActiveWorkspaceId() is the equivalent of LanguageNegotiationMethodInterface::getLangcode(), which returns a language ID, not a language object
  • WorkspaceNegotiatorInterface::setActiveWorkspace() is the equivalent of LanguageNegotiationMethodInterface::persist()

The URL workspace negotiatior, because the token comes from user input in the request, adds an additional token parameter (similar to the image style itok) so that we know that what has been passed in is actually a workspace ID or not, otherwise it wouldn't be able to validate the ID without trying to load a workspace, which would defeat the benefits of only having to return an ID.

Remaining tasks

Review.

User interface changes

Nope.

API changes

- \Drupal\workspaces\Negotiator\WorkspaceNegotiatorInterface::getActiveWorkspace() is deprecated, to be removed in Drupal 11.

Data model changes

Nope.

Release notes snippet

Nope.

πŸ“Œ Task
Status

Fixed

Version

10.3 ✨

Component
WorkspacesΒ  β†’

Last updated 3 days ago

No maintainer
Created by

πŸ‡·πŸ‡΄Romania amateescu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024