You are here

public function DomainAccessCurrentAllFilter::query in Domain Access 8

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides BooleanOperator::query

File

domain_access/src/Plugin/views/filter/DomainAccessCurrentAllFilter.php, line 43

Class

DomainAccessCurrentAllFilter
Handles matching of current domain.

Namespace

Drupal\domain_access\Plugin\views\filter

Code

public function query() {
  $this
    ->ensureMyTable();
  $all_table = $this->query
    ->addTable('node__field_domain_all_affiliates', $this->relationship);
  $all_field = $all_table . '.field_domain_all_affiliates_value';
  $real_field = $this->tableAlias . '.' . $this->realField;

  /** @var DomainNegotiatorInterface $domain_negotiator */
  $domain_negotiator = \Drupal::service('domain.negotiator');
  $current_domain = $domain_negotiator
    ->getActiveDomain();
  $current_domain_id = $current_domain
    ->id();
  if (empty($this->value)) {
    $where = "(({$real_field} <> '{$current_domain_id}' OR {$real_field} IS NULL) AND ({$all_field} = 0 OR {$all_field} IS NULL))";
    if ($current_domain
      ->isDefault()) {
      $where = "({$real_field} <> '{$current_domain_id}' AND ({$all_field} = 0 OR {$all_field} IS NULL))";
    }
  }
  else {
    $where = "({$real_field} = '{$current_domain_id}' OR {$all_field} = 1)";
    if ($current_domain
      ->isDefault()) {
      $where = "(({$real_field} = '{$current_domain_id}' OR {$real_field} IS NULL) OR {$all_field} = 1)";
    }
  }
  $this->query
    ->addWhereExpression($this->options['group'], $where);

  // This filter causes duplicates.
  $this->query->options['distinct'] = TRUE;
}