|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\Deriver\Fields; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Field\FieldDefinitionInterface; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\TypedData\ComplexDataDefinitionInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\TypedData\DataDefinitionInterface; |
|
|
|
|
|
|
8
|
|
|
use Drupal\Core\TypedData\DataReferenceDefinitionInterface; |
|
|
|
|
|
|
9
|
|
|
use Drupal\graphql\Utility\StringHelper; |
|
10
|
|
|
use Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverBase; |
|
11
|
|
|
|
|
12
|
|
|
class EntityFieldItemDeriver extends EntityFieldDeriverBase { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* {@inheritdoc} |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition) { |
|
18
|
|
|
$itemDefinition = $fieldDefinition->getItemDefinition(); |
|
19
|
|
|
if (!($itemDefinition instanceof ComplexDataDefinitionInterface) || !$propertyDefinitions = $itemDefinition->getPropertyDefinitions()) { |
|
20
|
|
|
return []; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
if (count($propertyDefinitions) <= 1) { |
|
24
|
|
|
return []; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$tags = array_merge($fieldDefinition->getCacheTags(), ['entity_field_info']); |
|
28
|
|
|
$contexts = $fieldDefinition->getCacheContexts(); |
|
29
|
|
|
$maxAge = $fieldDefinition->getCacheMaxAge(); |
|
30
|
|
|
|
|
31
|
|
|
$entityTypeId = $fieldDefinition->getTargetEntityTypeId(); |
|
32
|
|
|
$entityType = $this->entityTypeManager->getDefinition($entityTypeId); |
|
33
|
|
|
$supportsBundles = $entityType->hasKey('bundle'); |
|
34
|
|
|
$fieldName = $fieldDefinition->getName(); |
|
35
|
|
|
$fieldBundle = $fieldDefinition->getTargetBundle() ?: ''; |
|
36
|
|
|
|
|
37
|
|
|
$commonDefinition = [ |
|
38
|
|
|
'parents' => [StringHelper::camelCase('field', $entityTypeId, $supportsBundles ? $fieldBundle : '', $fieldName)], |
|
39
|
|
|
'schema_cache_tags' => $tags, |
|
40
|
|
|
'schema_cache_contexts' => $contexts, |
|
41
|
|
|
'schema_cache_max_age' => $maxAge, |
|
42
|
|
|
] + $basePluginDefinition; |
|
43
|
|
|
|
|
44
|
|
|
$derivatives = []; |
|
45
|
|
|
foreach ($propertyDefinitions as $property => $propertyDefinition) { |
|
46
|
|
|
$derivatives["$entityTypeId-$fieldName-$fieldBundle-$property"] = [ |
|
47
|
|
|
'name' => StringHelper::propCase($property), |
|
48
|
|
|
'description' => $propertyDefinition->getDescription(), |
|
49
|
|
|
'property' => $property, |
|
50
|
|
|
'type' => $this->extractDataType($propertyDefinition), |
|
51
|
|
|
] + $commonDefinition; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $derivatives; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Extracts the data type of a property's data definition. |
|
59
|
|
|
* |
|
60
|
|
|
* @param \Drupal\Core\TypedData\DataDefinitionInterface $propertyDefinition |
|
61
|
|
|
* The property's data definition. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
* The property's data type. |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function extractDataType(DataDefinitionInterface $propertyDefinition) { |
|
67
|
|
|
if ($propertyDefinition instanceof DataReferenceDefinitionInterface) { |
|
68
|
|
|
return $propertyDefinition->getTargetDefinition()->getDataType(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $propertyDefinition->getDataType(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
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