function ViewsQueryAlter::getRevisionTableJoin

Same name in other branches
  1. 9 core/modules/workspaces/src/ViewsQueryAlter.php \Drupal\workspaces\ViewsQueryAlter::getRevisionTableJoin()
  2. 8.9.x core/modules/workspaces/src/ViewsQueryAlter.php \Drupal\workspaces\ViewsQueryAlter::getRevisionTableJoin()
  3. 10 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

1 call to ViewsQueryAlter::getRevisionTableJoin()
ViewsQueryAlter::ensureRevisionTable in core/modules/workspaces/src/ViewsQueryAlter.php
Adds the revision table of an entity type to a query object.

File

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

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,
        'left_table' => $relationship,
        'left_formula' => "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'] = [
            [
                'field' => $langcode_field,
                'left_field' => $langcode_field,
            ],
        ];
    }
    
    /** @var \Drupal\views\Plugin\views\join\JoinPluginInterface $join */
    $join = $this->viewsJoinPluginManager
        ->createInstance('standard', $definition);
    $join->adjusted = TRUE;
    $this->adjustedTables[$join] = TRUE;
    return $join;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.