Skip to content

Commit 88a408a

Browse files
committed
Crude(?) fix attempt
1 parent 2dd75e8 commit 88a408a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/Type/DrupalStaticEntityQueryDynamicReturnTypeExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ public function getTypeFromStaticMethodCall(
5757
if ($type instanceof ConstantStringType) {
5858
$entityTypeId = $type->getValue();
5959
} else {
60-
// @todo determine what these types are, and try to resolve entity name from.
61-
return $returnType;
60+
// We're unsure what specific EntityQueryType it is, so let's stick
61+
// with the general class itself, so at least it gets access checked
62+
return new EntityQueryType(
63+
$returnType->getClassName(),
64+
$returnType->getSubtractedType(),
65+
$returnType->getClassReflection()
66+
);
6267
}
6368
$entityType = $this->entityDataRepository->get($entityTypeId);
6469
$entityStorageType = $entityType->getStorageType();

src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function getTypeFromMethodCall(
7272
? new ArrayType(new IntegerType(), new StringType())
7373
: new EntityQueryExecuteWithoutAccessCheckType(new IntegerType(), new StringType());
7474
}
75+
if ($varType instanceof EntityQueryType) {
76+
return $varType->hasAccessCheck()
77+
? new ArrayType(new IntegerType(), new StringType())
78+
: new EntityQueryExecuteWithoutAccessCheckType(new IntegerType(), new StringType());
79+
}
7580
return $defaultReturnType;
7681
}
7782

tests/src/Rules/data/bug-494.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,25 @@
55
class TestClass {
66

77
/**
8-
* Tests entity count queries with access check and unknown entity type.
8+
* Tests entity queries with access check and unknown entity type.
99
*/
1010
public function bug494(string $entity_type): void
1111
{
12+
\Drupal::entityQuery($entity_type)
13+
->accessCheck(FALSE)
14+
->condition('field_test', 'foo', '=')
15+
->execute();
16+
17+
\Drupal::entityQuery($entity_type)
18+
->condition('field_test', 'foo', '=')
19+
->accessCheck(FALSE)
20+
->execute();
21+
22+
\Drupal::entityQuery($entity_type)
23+
->condition('field_test', 'foo', '=')
24+
->accessCheck(FALSE)
25+
->execute();
26+
1227
\Drupal::entityQuery($entity_type)
1328
->accessCheck(FALSE)
1429
->condition('field_test', 'foo', '=')

0 commit comments

Comments
 (0)