You are here

public function PublishedOrHasRoles::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/PublishedOrHasRoles.php, line 64

Class

PublishedOrHasRoles
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);
  }
  if (empty($roles)) {

    // If there are no roles selected, not querying on roles.
    $this->query
      ->addWhereExpression($this->options['group'], "{$table}.status = 1\n        OR\n        ({$table}.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1)\n        OR\n        ***BYPASS_NODE_ACCESS*** = 1");
  }
  else {
    $this->query
      ->addWhereExpression($this->options['group'], "{$table}.status = 1\n        OR\n        ({$table}.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1)\n        OR\n        ***BYPASS_NODE_ACCESS*** = 1\n        OR\n        ***CURRENT_USER*** IN (SELECT ur.entity_id FROM {user__roles} ur WHERE ur.roles_target_id IN (:roles[]))", [
      ':roles[]' => $roles,
    ]);
  }
}