You are here

public function AccessControlHierarchyBase::addWhere in Workbench Access 8

Adds a where clause to a view when using a section filter.

Parameters

\Drupal\workbench_access\Plugin\views\filter\Section $filter: The views filter object provided by Workbench Access.

array $values: An array of values for the current view.

Overrides AccessControlHierarchyInterface::addWhere

File

src/AccessControlHierarchyBase.php, line 268

Class

AccessControlHierarchyBase
Defines a base hierarchy class that others may extend.

Namespace

Drupal\workbench_access

Code

public function addWhere(Section $filter, array $values) {

  // The JOIN data tells us if we have multiple tables to deal with.
  $join_data = $this
    ->getViewsJoin($filter
    ->getEntityType(), $filter->realField);
  if (count($join_data) == 1) {
    $filter->query
      ->addWhere($filter->options['group'], "{$filter->tableAlias}.{$filter->realField}", array_values($values), $filter->operator);
  }
  else {
    $or = new Condition('OR');
    foreach ($join_data as $field => $data) {
      $alias = $data['table_alias'] . '.' . $data['real_field'];
      $or
        ->condition($alias, array_values($values), $filter->operator);
    }
    $filter->query
      ->addWhere($filter->options['group'], $or);
  }
}