You are here

protected function ViewsQueryAlter::ensureWorkspaceAssociationTable in Workspace 8.2

Adds the 'workspace_association' table to a views query.

Parameters

string $entity_type_id: The ID of the entity type to join.

\Drupal\views\Plugin\views\query\Sql $query: The query plugin object for the query.

string $relationship: The primary table alias this table is related to.

Return value

string The alias of the 'workspace_association' table.

2 calls to ViewsQueryAlter::ensureWorkspaceAssociationTable()
ViewsQueryAlter::alterQueryForEntityType in src/ViewsQueryAlter.php
Alters the entity type tables for a Views query.
ViewsQueryAlter::ensureRevisionTable in src/ViewsQueryAlter.php
Adds the revision table of an entity type to a query object.

File

src/ViewsQueryAlter.php, line 274

Class

ViewsQueryAlter
Defines a class for altering views queries.

Namespace

Drupal\workspace

Code

protected function ensureWorkspaceAssociationTable($entity_type_id, Sql $query, $relationship) {
  if (isset($query->tables[$relationship]['workspace_association'])) {
    return $query->tables[$relationship]['workspace_association']['alias'];
  }
  $table_data = $this->viewsData
    ->get($query->relationships[$relationship]['base']);

  // Construct the join.
  $definition = [
    'table' => 'workspace_association',
    'field' => 'target_entity_id',
    'left_table' => $relationship,
    'left_field' => $table_data['table']['base']['field'],
    'extra' => [
      [
        'field' => 'target_entity_type_id',
        'value' => $entity_type_id,
      ],
      [
        'field' => 'workspace',
        'value' => $this->workspaceManager
          ->getActiveWorkspace()
          ->id(),
      ],
    ],
    'type' => 'LEFT',
  ];
  $join = $this->viewsJoinPluginManager
    ->createInstance('standard', $definition);
  $join->adjusted = TRUE;
  return $query
    ->queueTable('workspace_association', $relationship, $join);
}