You are here

protected function ViewsQueryAlter::getRevisionTableJoin in Drupal 10

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

Fetches a join for a revision table using the workspace_association table.

Parameters

string $relationship: The relationship to use in the view.

string $table: The table name.

string $field: The field to join on.

string $workspace_association_table: The alias of the 'workspace_association' table joined to the main entity table.

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type that is being queried.

Return value

\Drupal\views\Plugin\views\join\JoinPluginInterface An adjusted views join object to add to the query.

Throws

\Drupal\Component\Plugin\Exception\PluginException

File

core/modules/workspaces/src/ViewsQueryAlter.php, line 384

Class

ViewsQueryAlter
Defines a class for altering views queries.

Namespace

Drupal\workspaces

Code

protected function getRevisionTableJoin($relationship, $table, $field, $workspace_association_table, EntityTypeInterface $entity_type) {
  $definition = [
    'table' => $table,
    'field' => $field,
    // Making this explicitly NULL allows the left table to be a formula.
    'left_table' => NULL,
    'left_field' => "COALESCE({$workspace_association_table}.target_entity_revision_id, {$relationship}.{$field})",
  ];
  if ($entity_type
    ->isTranslatable() && $this->languageManager
    ->isMultilingual()) {
    $langcode_field = $entity_type
      ->getKey('langcode');
    $definition['extra'] = "{$table}.{$langcode_field} = {$relationship}.{$langcode_field}";
  }

  /** @var \Drupal\views\Plugin\views\join\JoinPluginInterface $join */
  $join = $this->viewsJoinPluginManager
    ->createInstance('standard', $definition);
  $join->adjusted = TRUE;
  $join->workspace_adjusted = TRUE;
  return $join;
}