protected function EntityFieldItemDeriver::getDerivativeDefinitionsFromFieldDefinition in GraphQL 8.3
Provides plugin definition values from fields.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition: Field definition object.
array $basePluginDefinition: Base definition array.
Return value
array The derived plugin definitions for the given field.
Overrides EntityFieldDeriverBase::getDerivativeDefinitionsFromFieldDefinition
File
- modules/
graphql_core/ src/ Plugin/ Deriver/ Fields/ EntityFieldItemDeriver.php, line 17
Class
Namespace
Drupal\graphql_core\Plugin\Deriver\FieldsCode
protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition) {
$itemDefinition = $fieldDefinition
->getItemDefinition();
if (!$itemDefinition instanceof ComplexDataDefinitionInterface || !($propertyDefinitions = $itemDefinition
->getPropertyDefinitions())) {
return [];
}
if (count($propertyDefinitions) <= 1) {
return [];
}
$tags = array_merge($fieldDefinition
->getCacheTags(), [
'entity_field_info',
]);
$contexts = $fieldDefinition
->getCacheContexts();
$maxAge = $fieldDefinition
->getCacheMaxAge();
$entityTypeId = $fieldDefinition
->getTargetEntityTypeId();
$entityType = $this->entityTypeManager
->getDefinition($entityTypeId);
$supportsBundles = $entityType
->hasKey('bundle');
$fieldName = $fieldDefinition
->getName();
$fieldBundle = $fieldDefinition
->getTargetBundle() ?: '';
$commonDefinition = [
'parents' => [
StringHelper::camelCase('field', $entityTypeId, $supportsBundles ? $fieldBundle : '', $fieldName),
],
'schema_cache_tags' => $tags,
'schema_cache_contexts' => $contexts,
'schema_cache_max_age' => $maxAge,
] + $basePluginDefinition;
$derivatives = [];
foreach ($propertyDefinitions as $property => $propertyDefinition) {
$derivatives["{$entityTypeId}-{$fieldName}-{$fieldBundle}-{$property}"] = [
'name' => StringHelper::propCase($property),
'description' => $propertyDefinition
->getDescription(),
'property' => $property,
'type' => $this
->extractDataType($propertyDefinition),
] + $commonDefinition;
}
return $derivatives;
}