class EntityFieldItemDeriver in GraphQL 8.3
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverBase implements ContainerDeriverInterface uses DependencySerializationTrait
- class \Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldItemDeriver
- class \Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverBase implements ContainerDeriverInterface uses DependencySerializationTrait
Expanded class hierarchy of EntityFieldItemDeriver
File
- modules/
graphql_core/ src/ Plugin/ Deriver/ Fields/ EntityFieldItemDeriver.php, line 12
Namespace
Drupal\graphql_core\Plugin\Deriver\FieldsView source
class EntityFieldItemDeriver extends EntityFieldDeriverBase {
/**
* {@inheritdoc}
*/
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;
}
/**
* Extracts the data type of a property's data definition.
*
* @param \Drupal\Core\TypedData\DataDefinitionInterface $propertyDefinition
* The property's data definition.
*
* @return string
* The property's data type.
*/
protected function extractDataType(DataDefinitionInterface $propertyDefinition) {
if ($propertyDefinition instanceof DataReferenceDefinitionInterface) {
return $propertyDefinition
->getTargetDefinition()
->getDataType();
}
return $propertyDefinition
->getDataType();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
EntityFieldDeriverBase:: |
protected | property | The base plugin id. | |
EntityFieldDeriverBase:: |
protected | property | The entity bundle info. | |
EntityFieldDeriverBase:: |
protected | property | The entity field manager. | |
EntityFieldDeriverBase:: |
protected | property | The entity type manager. | |
EntityFieldDeriverBase:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
EntityFieldDeriverBase:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
EntityFieldDeriverBase:: |
public | function | RawValueFieldItemDeriver constructor. | |
EntityFieldItemDeriver:: |
protected | function | Extracts the data type of a property's data definition. | |
EntityFieldItemDeriver:: |
protected | function |
Provides plugin definition values from fields. Overrides EntityFieldDeriverBase:: |