I’m writing a custom entity access handler for a custom entity that checks if a user has access to the underlying node. The checkAccess() code looks like this:
$uuid = $entity->uuid->getString(); if (isset($uuid)) { $nodes = $this->node->getQuery()->accessCheck(TRUE)->condition('uuid', $uuid)->execute(); if (!empty($nodes)) { return AccessResult::allowed(); } } return AccessResult::forbidden("Access denied.");
The problem is when I go to the jsonapi endpoint for the entity, I’m getting the error "The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\jsonapi\CacheableResourceResponse.
"
If I return accessResult::allowed() before the $nodes query it works. What’s happening here?