You are here

public function CurrentUserHasRoles::query in Views Published or Roles 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 FilterPluginBase::query

File

src/Plugin/views/filter/CurrentUserHasRoles.php, line 63

Class

CurrentUserHasRoles
Filter by published status and by role.

Namespace

Drupal\views_published_or_roles\Plugin\views\filter

Code

public function query() {
  $table = 'node_field_data';
  $roles = [];
  if (is_array($this->value)) {
    $roles = array_keys($this->value);
  }
  $this->query
    ->addWhereExpression($this->options['group'], '***CURRENT_USER*** IN (SELECT ur.entity_id FROM {user__roles} ur WHERE ur.roles_target_id IN (:roles[]))', [
    ':roles[]' => $roles,
  ]);
}