function ViewsQueryAlter::getRevisionTableJoin

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

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