Skip to content
Snippets Groups Projects

3401801 - Add grants

Files
5
@@ -9,8 +9,6 @@ use Drupal\node\Plugin\views\filter\Status;
* Filter by unpublished status.
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("node_unpublished_status")
*/
class UnpublishedStatus extends Status {
@@ -20,24 +18,21 @@ class UnpublishedStatus extends Status {
public function query() {
$table = $this->ensureMyTable();
$account = \Drupal::currentUser();
$query = "{$table}.status = 1 OR ({$table}.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***BYPASS_NODE_ACCESS*** = 1";
if ($this->moduleHandler->moduleExists('content_moderation')) {
$query .= ' OR ***VIEW_ANY_UNPUBLISHED_NODES*** = 1';
}
$query_addition = [];
$types = [];
/** @var \Drupal\node\NodeTypeInterface $type */
foreach (NodeType::loadMultiple() as $type) {
$type_id = $type->id();
if ($account->hasPermission("view $type_id unpublished content")) {
$query_addition[] = "$table.type = '$type_id'";
}
$types[] = "({$table}.type = '{$type_id}' AND ***VIEWUNPUBLISHED_TYPE_{$type_id}*** = 1)";
}
// 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) . ')';
if ($types !== []) {
$types = implode(' OR ', $types);
$query .= " OR $types";
}
$this->query->addWhereExpression($this->options['group'], $query);
@@ -48,7 +43,6 @@ class UnpublishedStatus extends Status {
*/
public function getCacheContexts() {
$contexts = parent::getCacheContexts();
$contexts[] = 'user.roles';
return $contexts;
Loading