public function UnpublishedStatus::query in Unpublished Node Permissions 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 Status::query
File
- src/
Plugin/ views/ filter/ UnpublishedStatus.php, line 20
Class
- UnpublishedStatus
- Filter by unpublished status.
Namespace
Drupal\unpublished_node_permissions\Plugin\views\filterCode
public function query() {
$table = $this
->ensureMyTable();
$account = \Drupal::currentUser();
$query_addition = [];
foreach (NodeType::loadMultiple() as $type) {
$type_id = $type
->id();
if ($account
->hasPermission("view {$type_id} unpublished content")) {
$query_addition[] = "{$table}.type = '{$type_id}'";
}
}
// Original node_status query.
$query = "{$table}.status = 1 OR ({$table}.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***BYPASS_NODE_ACCESS*** = 1";
// Add every allowed unpublished content type in an OR group.
// See \Drupal\node\Plugin\views\filter\Status.
if (count($query_addition)) {
$query .= ' OR ';
$query .= '(' . implode(' OR ', $query_addition) . ')';
}
$this->query
->addWhereExpression($this->options['group'], $query);
}