CiviCrmBridgeRelationshipBase.php in CiviCRM Entity 8.3
File
src/Plugin/views/relationship/CiviCrmBridgeRelationshipBase.php
View source
<?php
namespace Drupal\civicrm_entity\Plugin\views\relationship;
use Drupal\views\Plugin\views\relationship\RelationshipPluginBase;
use Drupal\views\Views;
class CiviCrmBridgeRelationshipBase extends RelationshipPluginBase {
public function query() {
$this
->ensureMyTable();
$views_data = Views::viewsData()
->get($this->table);
$left_field = $views_data['table']['base']['field'];
$first = [
'left_table' => $this->tableAlias,
'left_field' => $left_field,
'table' => $this->definition['table'],
'field' => $this->definition['first field'],
'adjusted' => TRUE,
];
if (!empty($this->definition['extra'])) {
$first['extra'] = $this->definition['extra'];
}
if (!empty($this->options['required'])) {
$first['type'] = 'INNER';
}
$first_join = Views::pluginManager('join')
->createInstance('standard', $first);
$first_alias = $this->query
->addTable($this->definition['table'], $this->relationship, $first_join);
$second = [
'left_table' => $first_alias,
'left_field' => $this->definition['second field'],
'table' => $this->definition['base'],
'field' => $this->definition['base field'],
'adjusted' => TRUE,
];
if (!empty($this->options['required'])) {
$second['type'] = 'INNER';
}
$second_join = Views::pluginManager('join')
->createInstance('standard', $second);
$second_join->adjusted = TRUE;
$alias = $this->definition['base'] . '_' . $this->definition['table'];
$this->alias = $this->query
->addRelationship($alias, $second_join, $this->definition['base'], $this->relationship);
}
}