You are here

public static function ContentEntityTypeResolver::getObjectTypeFromData in GraphQL 8.2

Same name and namespace in other branches
  1. 8 src/TypeResolver/ContentEntityTypeResolver.php \Drupal\graphql\TypeResolver\ContentEntityTypeResolver::getObjectTypeFromData()

Object type resolver callback for entity type schema interfaces.

Parameters

\Drupal\Core\Entity\Plugin\DataType\EntityAdapter $data: The object type of the given data.

Return value

\Fubhy\GraphQL\Type\Definition\Types\ObjectType|null The object type of the given data or NULL if it could not be resolved.

File

src/TypeResolver/ContentEntityTypeResolver.php, line 293

Class

ContentEntityTypeResolver
Resolves the schema for content entities.

Namespace

Drupal\graphql\TypeResolver

Code

public static function getObjectTypeFromData(EntityAdapter $data) {
  if (!($entity = $data
    ->getValue())) {
    return NULL;
  }
  $currentLanguage = \Drupal::service('language_manager')
    ->getCurrentLanguage();
  $loadedSchema = \Drupal::service('graphql.schema_loader')
    ->loadSchema($currentLanguage);
  $typeMap = $loadedSchema
    ->getTypeMap();
  $entityTypeId = $entity
    ->getEntityType()
    ->id();
  $bundleKey = $entity
    ->bundle();
  $typeIdentifier = 'entity:' . ($bundleKey !== $entityTypeId ? "{$entityTypeId}:{$bundleKey}" : $entityTypeId);
  $typeName = StringHelper::formatTypeName($typeIdentifier);
  return isset($typeMap[$typeName]) ? $typeMap[$typeName] : NULL;
}