Access Check Missing in UserConsentItem.php Causes Error

Created on 9 July 2023, over 1 year ago
Updated 6 June 2024, 6 months ago

Problem/Motivation

After installing the GDPR Consent module and attempting to add a Consent field to a User entity, I encounter the following error:

Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 141 of core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

This occurs when trying to complete the final step of the field addition process.

Proposed resolution

The solution is to add an explicit access check to the entity query in the UserConsentItem.php file. Here is the modified code:

$agreement_ids = \Drupal::entityQuery('gdpr_consent_agreement')
  ->condition('status', 1)
  ->accessCheck(TRUE)
  ->sort('title')
  ->execute();

$agreements = ConsentAgreement::loadMultiple($agreement_ids);

I've attached a patch with this change.

Steps to reproduce

Install the GDPR Consent module.
Try to add a Consent field to the User entity.
Follow the steps to add a field.
At the last step, the error appears.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇱Netherlands rbosscher

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024