Skip to content

Commit

Permalink
Use @phpstan-ignore-next-line on getAggregateQuery() lines to fix "Mi…
Browse files Browse the repository at this point in the history
…ssing explicit access check on entity query" errors.

This is a temporary workaround pending resolution of this upstream issue:

mglaman/phpstan-drupal#474
  • Loading branch information
mstenta committed Sep 12, 2022
1 parent 02fec2d commit df1c8be
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/core/ui/metrics/src/Plugin/Block/FarmMetricsBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ protected function getEntityMetrics($entity_type) {
$query->condition('status', 'active');
}

// @todo https://github.com/mglaman/phpstan-drupal/issues/474
// @phpstan-ignore-next-line
$count = $query->count()->execute();
$route_name = "view.farm_$entity_type.page_type";
$metrics[] = Link::createFromRoute($bundle_info['label'] . ': ' . $count, $route_name, ['arg_0' => $bundle], ['attributes' => ['class' => ['metric', 'button']]])->toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function access(RouteMatchInterface $route_match) {

// Run a count query to see if there are any assets that reference this
// asset as a parent.
// @todo https://github.com/mglaman/phpstan-drupal/issues/474
// @phpstan-ignore-next-line
$count = $this->assetStorage->getAggregateQuery()
->accessCheck(TRUE)
->condition('parent.entity.id', $asset_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function access(RouteMatchInterface $route_match) {
$query->condition($reference_condition);

// Determine access based on the log count.
// @todo https://github.com/mglaman/phpstan-drupal/issues/474
// @phpstan-ignore-next-line
$count = $query->execute();
$access = AccessResult::allowedIf($count > 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function validate($value, Constraint $constraint) {

// Query the number of birth logs that reference the asset.
// We do not check access to ensure that all matching logs are found.
// @todo https://github.com/mglaman/phpstan-drupal/issues/474
// @phpstan-ignore-next-line
$count = $this->entityTypeManager->getStorage('log')->getAggregateQuery()
->accessCheck(FALSE)
->condition('type', 'birth')
Expand Down

0 comments on commit df1c8be

Please sign in to comment.