You are here

protected function JoinPluginBase::buildExtra 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::buildExtra()
  2. 9 core/modules/views/src/Plugin/views/join/JoinPluginBase.php \Drupal\views\Plugin\views\join\JoinPluginBase::buildExtra()

Builds a single extra condition.

Parameters

array $info: The extra information. See JoinPluginBase::$extra for details.

array $arguments: Array of query arguments.

array $table: The right table.

\Drupal\Core\Database\Query\SelectInterface $select_query: The current select query being built.

array $left: The left table.

Return value

string The extra condition

2 calls to JoinPluginBase::buildExtra()
FieldOrLanguageJoin::joinAddExtra in core/modules/views/src/Plugin/views/join/FieldOrLanguageJoin.php
Adds the extras to the join condition.
JoinPluginBase::joinAddExtra in core/modules/views/src/Plugin/views/join/JoinPluginBase.php
Adds the extras to the join condition.

File

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

Class

JoinPluginBase

Namespace

Drupal\views\Plugin\views\join

Code

protected function buildExtra($info, &$arguments, $table, SelectInterface $select_query, $left) {

  // Do not require 'value' to be set; allow for field syntax instead.
  $info += [
    'value' => NULL,
  ];

  // Figure out the table name. Remember, only use aliases provided
  // if at all possible.
  $join_table = '';
  if (!array_key_exists('table', $info)) {
    $join_table = $table['alias'] . '.';
  }
  elseif (isset($info['table'])) {

    // If we're aware of a table alias for this table, use the table
    // alias instead of the table name.
    if (isset($left) && $left['table'] == $info['table']) {
      $join_table = $left['alias'] . '.';
    }
    else {
      $join_table = $info['table'] . '.';
    }
  }

  // Convert a single-valued array of values to the single-value case,
  // and transform from IN() notation to = notation
  if (is_array($info['value']) && count($info['value']) == 1) {
    $info['value'] = array_shift($info['value']);
  }
  if (is_array($info['value'])) {

    // We use an SA-CORE-2014-005 conformant placeholder for our array
    // of values. Also, note that the 'IN' operator is implicit.
    // @see https://www.drupal.org/node/2401615.
    $operator = !empty($info['operator']) ? $info['operator'] : 'IN';
    $placeholder = ':views_join_condition_' . $select_query
      ->nextPlaceholder() . '[]';
    $placeholder_sql = "( {$placeholder} )";
  }
  else {

    // With a single value, the '=' operator is implicit.
    $operator = !empty($info['operator']) ? $info['operator'] : '=';
    $placeholder = $placeholder_sql = ':views_join_condition_' . $select_query
      ->nextPlaceholder();
  }

  // Set 'field' as join table field if available or set 'left field' as
  // join table field is not set.
  if (isset($info['field'])) {
    $join_table_field = "{$join_table}{$info['field']}";

    // Allow the value to be set either with the 'value' element or
    // with 'left_field'.
    if (isset($info['left_field'])) {
      $placeholder_sql = "{$left['alias']}.{$info['left_field']}";
    }
    else {
      $arguments[$placeholder] = $info['value'];
    }
  }
  else {
    $join_table_field = "{$left['alias']}.{$info['left_field']}";
    $arguments[$placeholder] = $info['value'];
  }

  // Render out the SQL fragment with parameters.
  return "{$join_table_field} {$operator} {$placeholder_sql}";
}