1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\Deriver\Fields; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\Derivative\DeriverBase; |
|
|
|
|
6
|
|
|
use Drupal\Core\Entity\EntityFieldManagerInterface; |
|
|
|
|
7
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
|
8
|
|
|
use Drupal\Core\Entity\FieldableEntityInterface; |
|
|
|
|
9
|
|
|
use Drupal\Core\Field\BaseFieldDefinition; |
|
|
|
|
10
|
|
|
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; |
|
|
|
|
11
|
|
|
use Drupal\Core\StringTranslation\StringTranslationTrait; |
|
|
|
|
12
|
|
|
use Drupal\Core\TypedData\TypedDataManagerInterface; |
|
|
|
|
13
|
|
|
use Drupal\graphql\Utility\StringHelper; |
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
15
|
|
|
|
16
|
|
|
class EntityReferenceQueryDeriver extends DeriverBase implements ContainerDeriverInterface { |
17
|
|
|
use StringTranslationTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The entity type manager. |
21
|
|
|
* |
22
|
|
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface |
23
|
|
|
*/ |
24
|
|
|
protected $entityTypeManager; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The entity field manager. |
28
|
|
|
* |
29
|
|
|
* @var \Drupal\Core\Entity\EntityFieldManagerInterface |
30
|
|
|
*/ |
31
|
|
|
protected $entityFieldManager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The typed data manager service. |
35
|
|
|
* |
36
|
|
|
* @var \Drupal\Core\TypedData\TypedDataManagerInterface |
37
|
|
|
*/ |
38
|
|
|
protected $typedDataManager; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public static function create(ContainerInterface $container, $basePluginId) { |
44
|
|
|
return new static( |
45
|
|
|
$container->get('entity_type.manager'), |
46
|
|
|
$container->get('entity_field.manager'), |
47
|
|
|
$container->get('typed_data_manager') |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* RawValueFieldItemDeriver constructor. |
53
|
|
|
* |
54
|
|
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
55
|
|
|
* The entity type manager. |
56
|
|
|
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager |
57
|
|
|
* The entity field manager. |
58
|
|
|
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typedDataManager |
59
|
|
|
* The typed data manager service. |
60
|
|
|
*/ |
61
|
|
|
public function __construct( |
62
|
|
|
EntityTypeManagerInterface $entityTypeManager, |
63
|
|
|
EntityFieldManagerInterface $entityFieldManager, |
64
|
|
|
TypedDataManagerInterface $typedDataManager |
65
|
|
|
) { |
66
|
|
|
$this->entityTypeManager = $entityTypeManager; |
67
|
|
|
$this->entityFieldManager = $entityFieldManager; |
68
|
|
|
$this->typedDataManager = $typedDataManager; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function getDerivativeDefinitions($basePluginDefinition) { |
75
|
|
|
$fieldMap = $this->entityFieldManager->getFieldMap(); |
76
|
|
|
|
77
|
|
|
foreach ($this->entityTypeManager->getDefinitions() as $entityTypeId => $entityType) { |
78
|
|
|
$interfaces = class_implements($entityType->getClass()); |
79
|
|
|
if (!array_key_exists(FieldableEntityInterface::class, $interfaces)) { |
80
|
|
|
continue; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
foreach ($this->entityFieldManager->getFieldStorageDefinitions($entityTypeId) as $fieldDefinition) { |
84
|
|
|
if ($fieldDefinition->getType() !== 'entity_reference' || !$targetTypeId = $fieldDefinition->getSetting('target_type')) { |
85
|
|
|
continue; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$tags = array_merge($fieldDefinition->getCacheTags(), ['entity_field_info']); |
89
|
|
|
$contexts = $fieldDefinition->getCacheContexts(); |
90
|
|
|
$maxAge = $fieldDefinition->getCacheMaxAge(); |
91
|
|
|
|
92
|
|
|
$targetType = $this->entityTypeManager->getDefinition($targetTypeId); |
93
|
|
|
$fieldName = $fieldDefinition->getName(); |
94
|
|
|
|
95
|
|
|
if ($fieldDefinition instanceof BaseFieldDefinition || !$entityType->hasKey('bundle')) { |
96
|
|
|
$parents = [StringHelper::camelCase($entityTypeId)]; |
97
|
|
|
} |
98
|
|
|
else { |
99
|
|
|
$parents = []; |
100
|
|
|
foreach ($fieldMap[$entityTypeId][$fieldName]['bundles'] as $bundle) { |
101
|
|
|
$parents[] = StringHelper::camelCase($entityTypeId . '_' . $bundle); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
$derivative = [ |
105
|
|
|
'parents' => $parents, |
106
|
|
|
'name' => StringHelper::propCase('query', $fieldName), |
107
|
|
|
'description' => $this->t('Query reference: @description', [ |
108
|
|
|
'@description' => $fieldDefinition->getDescription(), |
109
|
|
|
]), |
110
|
|
|
'field' => $fieldName, |
111
|
|
|
'entity_key' => $targetType->getKey('id'), |
112
|
|
|
'entity_type' => $targetTypeId, |
113
|
|
|
'schema_cache_tags' => $tags, |
114
|
|
|
'schema_cache_contexts' => $contexts, |
115
|
|
|
'schema_cache_max_age' => $maxAge, |
116
|
|
|
] + $basePluginDefinition; |
117
|
|
|
|
118
|
|
|
/** @var \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface $definition */ |
119
|
|
|
$this->derivatives["$entityTypeId-$fieldName"] = $derivative; |
|
|
|
|
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this->derivatives; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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