You are here

Views join handler plugins in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/join/JoinPluginBase.php \Drupal\views\Plugin\views\join\views_join_handlers

Handler plugins for Views table joins.

Handler plugins help build the view query object. Join handler plugins handle table joins.

Views join handlers extend \Drupal\views\Plugin\views\join\JoinPluginBase. They must be annotated with \Drupal\views\Annotation\ViewsJoin annotation, and they must be in namespace directory Plugin\views\join.

Here are some examples of how to join from table one to table two so it produces the following SQL:


INNER JOIN {two} ON one.field_a = two.field_b

The required php code for this kind of functionality is the following:

$configuration = array(
  'table' => 'two',
  'field' => 'field_b',
  'left_table' => 'one',
  'left_field' => 'field_a',
  'operator' => '=',
);
$join = Views::pluginManager('join')
  ->createInstance('standard', $configuration);

INNER JOIN {two} ON one.field_a = two.field_b AND one.field_c = 'some_val'

The required php code for this kind of functionality is the following:

$configuration = array(
  'table' => 'two',
  'field' => 'field_b',
  'left_table' => 'one',
  'left_field' => 'field_a',
  'operator' => '=',
  'extra' => array(
    0 => array(
      'left_field' => 'field_c',
      'value' => 'some_val',
    ),
  ),
);
$join = Views::pluginManager('join')
  ->createInstance('standard', $configuration);

INNER JOIN {two} ON one.field_a = two.field_b AND two.field_d = 'other_val'

The required php code for this kind of functionality is the following:

$configuration = array(
  'table' => 'two',
  'field' => 'field_b',
  'left_table' => 'one',
  'left_field' => 'field_a',
  'operator' => '=',
  'extra' => array(
    0 => array(
      'field' => 'field_d',
      'value' => 'other_val',
    ),
  ),
);
$join = Views::pluginManager('join')
  ->createInstance('standard', $configuration);

INNER JOIN {two} ON one.field_a = two.field_b AND one.field_c = two.field_d

The required php code for this kind of functionality is the following:

$configuration = array(
  'table' => 'two',
  'field' => 'field_b',
  'left_table' => 'one',
  'left_field' => 'field_a',
  'operator' => '=',
  'extra' => array(
    0 => array(
      'left_field' => 'field_c',
      'field' => 'field_d',
    ),
  ),
);
$join = Views::pluginManager('join')
  ->createInstance('standard', $configuration);

Here is an example of a more complex join:

class JoinComplex extends JoinPluginBase {
  public function buildJoin($select_query, $table, $view_query) {

    // Add an additional hardcoded condition to the query.
    $this->extra = 'foo.bar = baz.boing';
    parent::buildJoin($select_query, $table, $view_query);
  }

}

See also

Plugin API

Parent topics

File

core/modules/views/src/Plugin/views/join/JoinPluginBase.php, line 12
Contains \Drupal\views\Plugin\views\join\JoinPluginBase.

Classes

Namesort descending Location Description
JoinPluginBase core/modules/views/src/Plugin/views/join/JoinPluginBase.php Represents a join and creates the SQL necessary to implement the join.
Standard core/modules/views/src/Plugin/views/join/Standard.php Default implementation of the join plugin.
Subquery core/modules/views/src/Plugin/views/join/Subquery.php Join handler for relationships that join with a subquery as the left field.
ViewsJoin core/modules/views/src/Annotation/ViewsJoin.php Defines a Plugin annotation object for views join plugins.