EntityFieldTypeDeriver.php in GraphQL 8.3
File
modules/graphql_core/src/Plugin/Deriver/Types/EntityFieldTypeDeriver.php
View source
<?php
namespace Drupal\graphql_core\Plugin\Deriver\Types;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\TypedData\ComplexDataDefinitionInterface;
use Drupal\graphql\Utility\StringHelper;
use Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverBase;
class EntityFieldTypeDeriver extends EntityFieldDeriverBase {
protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition) {
$itemDefinition = $fieldDefinition
->getItemDefinition();
if (!$itemDefinition instanceof ComplexDataDefinitionInterface || !($propertyDefinitions = $itemDefinition
->getPropertyDefinitions())) {
return [];
}
$propertyDefinitions = $itemDefinition
->getPropertyDefinitions();
if (count($propertyDefinitions) <= 1) {
return [];
}
$entityTypeId = $fieldDefinition
->getTargetEntityTypeId();
$entityType = $this->entityTypeManager
->getDefinition($entityTypeId);
$supportsBundles = $entityType
->hasKey('bundle');
$fieldName = $fieldDefinition
->getName();
$fieldBundle = $fieldDefinition
->getTargetBundle() ?: '';
return [
"{$entityTypeId}-{$fieldName}-{$fieldBundle}" => [
'name' => StringHelper::camelCase('field', $entityTypeId, $supportsBundles ? $fieldBundle : '', $fieldName),
'description' => $fieldDefinition
->getDescription(),
'entity_type' => $entityTypeId,
'entity_bundle' => $fieldBundle ?: NULL,
'field_name' => $fieldName,
] + $basePluginDefinition,
];
}
}