You are here

protected function Tables::addJoin in Drupal 9

Same name in this branch
  1. 9 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addJoin()
  2. 9 core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::addJoin()
Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::addJoin()

Adds a join to a given table.

Parameters

string $type: The join type.

string $table: The table to join to.

string $join_condition: The condition on which to join to.

string $langcode: The langcode we use on the join.

string|null $delta: (optional) A delta which should be used as additional condition.

Return value

string Returns the alias of the joined table.

3 calls to Tables::addJoin()
Tables::addJoin in core/modules/workspaces/src/EntityQuery/Tables.php
Adds a join to a given table.
Tables::ensureEntityTable in core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
Joins the entity table, if necessary, and returns the alias for it.
Tables::ensureFieldTable in core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
Ensure the field table is joined if necessary.
1 method overrides Tables::addJoin()
Tables::addJoin in core/modules/workspaces/src/EntityQuery/Tables.php
Adds a join to a given table.

File

core/lib/Drupal/Core/Entity/Query/Sql/Tables.php, line 431

Class

Tables
Adds tables and fields to the SQL entity query.

Namespace

Drupal\Core\Entity\Query\Sql

Code

protected function addJoin($type, $table, $join_condition, $langcode, $delta = NULL) {
  $arguments = [];
  if ($langcode) {
    $entity_type_id = $this->sqlQuery
      ->getMetaData('entity_type');
    $entity_type = $this->entityTypeManager
      ->getActiveDefinition($entity_type_id);

    // Only the data table follows the entity language key, dedicated field
    // tables have a hard-coded 'langcode' column.
    $langcode_key = $entity_type
      ->getDataTable() == $table ? $entity_type
      ->getKey('langcode') : 'langcode';
    $placeholder = ':langcode' . $this->sqlQuery
      ->nextPlaceholder();
    $join_condition .= ' AND [%alias].[' . $langcode_key . '] = ' . $placeholder;
    $arguments[$placeholder] = $langcode;
  }
  if (isset($delta)) {
    $placeholder = ':delta' . $this->sqlQuery
      ->nextPlaceholder();
    $join_condition .= ' AND [%alias].[delta] = ' . $placeholder;
    $arguments[$placeholder] = $delta;
  }
  return $this->sqlQuery
    ->addJoin($type, $table, NULL, $join_condition, $arguments);
}