class Subquery in Views (for Drupal 7) 8.3
Join handler for relationships that join with a subquery as the left field. eg: LEFT JOIN node node_term_data ON ([YOUR SUBQUERY HERE]) = node_term_data.nid
join definition same as Join class above, except:
- left_query: The subquery to use in the left side of the join clause.
Plugin annotation
@Plugin(
id = "subquery"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\views\Plugin\views\join\JoinPluginBase
- class \Drupal\views\Plugin\views\join\Subquery
- class \Drupal\views\Plugin\views\join\JoinPluginBase
Expanded class hierarchy of Subquery
File
- lib/
Drupal/ views/ Plugin/ views/ join/ Subquery.php, line 25 - Definition of Drupal\views\Plugin\views\join\Subquery.
Namespace
Drupal\views\Plugin\views\joinView source
class Subquery extends JoinPluginBase {
/**
* Constructs a Subquery object.
*/
public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) {
parent::__construct($configuration, $plugin_id, $discovery);
$this->left_query = $this->configuration['left_query'];
}
/**
* Build the SQL for the join this object represents.
*
* @param $select_query
* An implementation of SelectQueryInterface.
* @param $table
* The base table to join.
* @param $view_query
* The source query, implementation of views_plugin_query.
* @return
*
*/
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'];
}
// Add our join condition, using a subquery on the left instead of a field.
$condition = "({$this->left_query}) = {$table['alias']}.{$this->field}";
$arguments = array();
// Tack on the extra.
// This is just copied verbatim from the parent class, which itself has a bug: http://drupal.org/node/1118100
if (isset($this->extra)) {
if (is_array($this->extra)) {
$extras = array();
foreach ($this->extra as $info) {
$extra = '';
// 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'])) {
$join_table = $info['table'] . '.';
}
$placeholder = ':views_join_condition_' . $select_query
->nextPlaceholder();
if (is_array($info['value'])) {
$operator = !empty($info['operator']) ? $info['operator'] : 'IN';
// Transform from IN() notation to = notation if just one value.
if (count($info['value']) == 1) {
$info['value'] = array_shift($info['value']);
$operator = $operator == 'NOT IN' ? '!=' : '=';
}
}
else {
$operator = !empty($info['operator']) ? $info['operator'] : '=';
}
$extras[] = "{$join_table}{$info['field']} {$operator} {$placeholder}";
$arguments[$placeholder] = $info['value'];
}
if ($extras) {
if (count($extras) == 1) {
$condition .= ' AND ' . array_shift($extras);
}
else {
$condition .= ' AND (' . implode(' ' . $this->extraOperator . ' ', $extras) . ')';
}
}
}
elseif ($this->extra && is_string($this->extra)) {
$condition .= " AND ({$this->extra})";
}
}
$select_query
->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JoinPluginBase:: |
public | property | Defines whether a join has been adjusted. | |
JoinPluginBase:: |
public | property |
The configuration array passed by initJoin. Overrides PluginBase:: |
|
JoinPluginBase:: |
public | property | An array of extra conditions on the join. | |
JoinPluginBase:: |
public | property | How all the extras will be combined. Either AND or OR. | |
JoinPluginBase:: |
public | property | The field to join on (right field). | |
JoinPluginBase:: |
public | property | The field we join to. | |
JoinPluginBase:: |
public | property | The table we join to. | |
JoinPluginBase:: |
public | property | The table to join (right table). | |
JoinPluginBase:: |
public | property | The join type, so for example LEFT (default) or INNER. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
Subquery:: |
public | function |
Build the SQL for the join this object represents. Overrides JoinPluginBase:: |
|
Subquery:: |
public | function |
Constructs a Subquery object. Overrides JoinPluginBase:: |