You are here

public function Tables::addWorkspaceAssociationJoin in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addWorkspaceAssociationJoin()
  2. 9 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addWorkspaceAssociationJoin()

Adds a new join to the 'workspace_association' table for an entity base table.

This method assumes that the active workspace has already been determined to be a non-default workspace.

Parameters

string $entity_type_id: The ID of the entity type whose base table we are joining.

string $base_table_alias: The alias of the entity type's base table.

string $active_workspace_id: The ID of the active workspace.

Return value

string The alias of the joined table.

1 call to Tables::addWorkspaceAssociationJoin()
Tables::addNextBaseTable in core/modules/workspaces/src/EntityQuery/Tables.php

File

core/modules/workspaces/src/EntityQuery/Tables.php, line 143

Class

Tables
Alters entity queries to use a workspace revision instead of the default one.

Namespace

Drupal\workspaces\EntityQuery

Code

public function addWorkspaceAssociationJoin($entity_type_id, $base_table_alias, $active_workspace_id) {
  if (!isset($this->contentWorkspaceTables[$base_table_alias])) {
    $entity_type = $this->entityTypeManager
      ->getActiveDefinition($entity_type_id);
    $id_field = $entity_type
      ->getKey('id');

    // LEFT join the Workspace association entity's table so we can properly
    // include live content along with a possible workspace-specific revision.
    $this->contentWorkspaceTables[$base_table_alias] = $this->sqlQuery
      ->leftJoin('workspace_association', NULL, "[%alias].[target_entity_type_id] = '{$entity_type_id}' AND [%alias].[target_entity_id] = [{$base_table_alias}].[{$id_field}] AND [%alias].[workspace] = '{$active_workspace_id}'");
    $this->baseTablesEntityType[$base_table_alias] = $entity_type
      ->id();
  }
  return $this->contentWorkspaceTables[$base_table_alias];
}