You are here

public function Tables::addWorkspaceAssociationJoin in Workspace 8.2

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 src/EntityQuery/Tables.php
Add the next entity base table.

File

src/EntityQuery/Tables.php, line 141

Class

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

Namespace

Drupal\workspace\EntityQuery

Code

public function addWorkspaceAssociationJoin($entity_type_id, $base_table_alias, $active_workspace_id) {
  if (!isset($this->contentWorkspaceTables[$base_table_alias])) {
    $entity_type = $this->entityManager
      ->getDefinition($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];
}