You are here

public function JoinPluginBase::buildJoin in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/join/JoinPluginBase.php \Drupal\views\Plugin\views\join\JoinPluginBase::buildJoin()
  2. 9 core/modules/views/src/Plugin/views/join/JoinPluginBase.php \Drupal\views\Plugin\views\join\JoinPluginBase::buildJoin()

Builds the SQL for the join this object represents.

When possible, try to use table alias instead of table names.

Parameters

$select_query: A select query object.

$table: The base table to join.

\Drupal\views\Plugin\views\query\QueryPluginBase $view_query: The source views query.

Overrides JoinPluginInterface::buildJoin

1 method overrides JoinPluginBase::buildJoin()
JoinTest::buildJoin in core/modules/views/tests/modules/views_test_data/src/Plugin/views/join/JoinTest.php
Builds the SQL for the join this object represents.

File

core/modules/views/src/Plugin/views/join/JoinPluginBase.php, line 297

Class

JoinPluginBase

Namespace

Drupal\views\Plugin\views\join

Code

public function buildJoin($select_query, $table, $view_query) {
  if (empty($this->configuration['table formula'])) {
    $right_table = $this->table;
  }
  else {
    $right_table = $this->configuration['table formula'];
  }
  if ($this->leftTable) {
    $left_table = $view_query
      ->getTableInfo($this->leftTable);
    $left_field = $this->leftFormula ?: "{$left_table['alias']}.{$this->leftField}";
  }
  else {

    // This can be used if left_field is a formula or something. It should be used only *very* rarely.
    $left_field = $this->leftField;
    $left_table = NULL;
  }
  $condition = "{$left_field} " . $this->configuration['operator'] . " {$table['alias']}.{$this->field}";
  $arguments = [];

  // Tack on the extra.
  if (isset($this->extra)) {
    $this
      ->joinAddExtra($arguments, $condition, $table, $select_query, $left_table);
  }
  $select_query
    ->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
}