You are here

public function JoinPluginBase::buildJoin in Drupal 8

Same name and namespace in other branches
  1. 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: An 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 call to 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.
2 methods override 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.
Subquery::buildJoin in core/modules/views/src/Plugin/views/join/Subquery.php
Builds the SQL for the join this object represents.

File

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

Class

JoinPluginBase
Represents a join and creates the SQL necessary to implement the join.

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} = {$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);
}