You are here

public function EntityReverse::query in CiviCRM Entity 8.3

Called to implement a relationship in a query.

Overrides EntityReverse::query

File

src/Plugin/views/relationship/EntityReverse.php, line 20

Class

EntityReverse
A relationship handlers which reverse CiviCRM entity references.

Namespace

Drupal\civicrm_entity\Plugin\views\relationship

Code

public function query() {
  $this
    ->ensureMyTable();
  $join = [
    'left_table' => $this->tableAlias,
    'left_field' => $this->definition['base field'],
    'table' => $this->definition['base'],
    'field' => $this->definition['field_name'],
    'adjusted' => TRUE,
  ];
  if (!empty($this->options['required'])) {
    $join['type'] = 'INNER';
  }
  if (!empty($this->definition['extra'])) {
    $join['extra'] = $this->definition['extra'];
  }
  if (!empty($def['join_id'])) {
    $id = $def['join_id'];
  }
  else {
    $id = 'standard';
  }
  $join_instance = $this->joinManager
    ->createInstance($id, $join);
  $join_instance->adjusted = TRUE;
  $alias = $this->definition['field_name'] . '_' . $this->table;
  $this->alias = $this->query
    ->addRelationship($alias, $join_instance, $this->definition['base'], $this->relationship);
}