|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\DependencyInjection\DependencySerializationTrait; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Entity\ContentEntityInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\Entity\Query\QueryInterface; |
|
|
|
|
|
|
8
|
|
|
use Drupal\graphql\GraphQL\Execution\ResolveContext; |
|
9
|
|
|
use Drupal\graphql_core\Plugin\GraphQL\Fields\EntityQuery\EntityQuery; |
|
10
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Query entities of the same type without the context's entity. |
|
14
|
|
|
* |
|
15
|
|
|
* @GraphQLField( |
|
16
|
|
|
* id = "entity_query_exclusive", |
|
17
|
|
|
* name = "entityQueryExclusive", |
|
18
|
|
|
* secure = true, |
|
19
|
|
|
* type = "EntityQueryResult!", |
|
20
|
|
|
* parents = {"Entity"}, |
|
21
|
|
|
* arguments = { |
|
22
|
|
|
* "filter" = "EntityQueryFilterInput", |
|
23
|
|
|
* "sort" = "[EntityQuerySortInput]", |
|
24
|
|
|
* "offset" = { |
|
25
|
|
|
* "type" = "Int", |
|
26
|
|
|
* "default" = 0 |
|
27
|
|
|
* }, |
|
28
|
|
|
* "limit" = { |
|
29
|
|
|
* "type" = "Int", |
|
30
|
|
|
* "default" = 10 |
|
31
|
|
|
* }, |
|
32
|
|
|
* "revisions" = { |
|
33
|
|
|
* "type" = "EntityQueryRevisionMode", |
|
34
|
|
|
* "default" = "default" |
|
35
|
|
|
* }, |
|
36
|
|
|
* "bundles" = { |
|
37
|
|
|
* "type" = "EntityQueryBundleMode", |
|
38
|
|
|
* "default" = "same" |
|
39
|
|
|
* } |
|
40
|
|
|
* } |
|
41
|
|
|
* ) |
|
42
|
|
|
*/ |
|
43
|
|
|
class EntityQueryExclusive extends EntityQuery { |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function getBaseQuery($value, array $args, ResolveContext $context, ResolveInfo $info) { |
|
49
|
|
|
if ($value instanceof ContentEntityInterface) { |
|
50
|
|
|
$type = $value->getEntityType(); |
|
51
|
|
|
$id = $type->getKey('id'); |
|
52
|
|
|
|
|
53
|
|
|
// Filter out the current entity. |
|
54
|
|
|
$query = parent::getBaseQuery($value, $args, $context, $info); |
|
55
|
|
|
$query->condition($id, $value->id(), '<>'); |
|
56
|
|
|
|
|
57
|
|
|
if (array_key_exists('bundles', $args)) { |
|
58
|
|
|
$query = $this->applyBundleMode($query, $value, $args['bundles']); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $query; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Apply the specified bundle filtering mode to the query. |
|
67
|
|
|
* |
|
68
|
|
|
* @param \Drupal\Core\Entity\Query\QueryInterface $query |
|
69
|
|
|
* The entity query object. |
|
70
|
|
|
* @param \Drupal\Core\Entity\ContentEntityInterface $value |
|
71
|
|
|
* The parent entity object. |
|
72
|
|
|
* @param mixed $mode |
|
73
|
|
|
* The revision query mode. |
|
74
|
|
|
* |
|
75
|
|
|
* @return \Drupal\Core\Entity\Query\QueryInterface The entity query object. |
|
76
|
|
|
* The entity query object. |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function applyBundleMode(QueryInterface $query, ContentEntityInterface $value, $mode) { |
|
79
|
|
|
if ($mode === 'same') { |
|
80
|
|
|
$type = $value->getEntityType(); |
|
81
|
|
|
|
|
82
|
|
|
if ($type->hasKey('bundle')) { |
|
83
|
|
|
$bundle = $type->getKey('bundle'); |
|
84
|
|
|
$query->condition($bundle, $value->bundle()); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $query; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths