Node access record filtering in views queries

Created on 7 May 2025, 3 days ago

Problem/Motivation

The way the access checks are added to the query in docroot/core/modules/node/src/Plugin/views/filter/Access.php
breaks the implementation in docroot/core/modules/views/src/Plugin/views/query/QueryPluginBase.php
with the following error:
TypeError: Unsupported operand types: string + int in Drupal\views\Plugin\views\query\QueryPluginBase->setWhereGroup() (line 181 of core/modules/views/src/Plugin/views/query/QueryPluginBase.php).

Steps to reproduce

Drupal 10.2 - access view filtered by node access record as user id != 1

Proposed resolution

Add conditions to the default group (0, '', Null) in Access.php.

--- a/docroot/core/modules/node/src/Plugin/views/filter/Access.php
+++ b/docroot/core/modules/node/src/Plugin/views/filter/Access.php
@@ -39,8 +39,8 @@ public function query() {
         }
       }
 
-      $this->query->addWhere('AND', $grants);
-      $this->query->addWhere('AND', $table . '.grant_view', 1, '>=');
+      $this->query->addWhere(0, $grants);
+      $this->query->addWhere(0, $table . '.grant_view', 1, '>=');
     }
   }
 

Remaining tasks

🐛 Bug report
Status

Active

Version

10.2

Component

node system

Created by

🇷🇴Romania reszli Târgu Mureș

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024