protected function ContentEntityTypeResolver::getEntityTypeFieldMap in GraphQL 8
Same name and namespace in other branches
- 8.2 src/TypeResolver/ContentEntityTypeResolver.php \Drupal\graphql\TypeResolver\ContentEntityTypeResolver::getEntityTypeFieldMap()
Helper function to retrieve the field schema definitions for an entity.
Retrieves the field schema definitions for the base properties and the bundle specific properties for each available bundle.
Parameters
string $entityTypeId: The entity type for which to build the field schema definitions.
Return value
array A structured array containing the field schema definitions for the base- and bundle specific properties.
1 call to ContentEntityTypeResolver::getEntityTypeFieldMap()
- ContentEntityTypeResolver::resolveRecursive in src/
TypeResolver/ ContentEntityTypeResolver.php
File
- src/
TypeResolver/ ContentEntityTypeResolver.php, line 157
Class
- ContentEntityTypeResolver
- Resolves the schema for content entities.
Namespace
Drupal\graphql\TypeResolverCode
protected function getEntityTypeFieldMap($entityTypeId) {
/** @var \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface $baseDefinition */
$baseDefinition = $this->typedDataManager
->createDataDefinition("entity:{$entityTypeId}");
// Resolve fields from base properties.
$baseFields = $this
->resolveFields($baseDefinition);
$baseFieldNames = StringHelper::formatPropertyNameList(array_keys($baseFields));
// Store the resolved base fields in the field map.
$fieldMap['base'] = array_filter(array_combine($baseFieldNames, $baseFields));
// The bundles available for this entity type.
$bundleInfo = $this->entityManager
->getBundleInfo($entityTypeId);
$bundleKeys = array_keys($bundleInfo);
$availableBundles = array_diff($bundleKeys, [
$entityTypeId,
]);
foreach ($availableBundles as $bundleKey) {
/** @var \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface $bundleDefinition */
$bundleDefinition = $this->typedDataManager
->createDataDefinition("entity:{$entityTypeId}:{$bundleKey}");
$bundleFields = $this
->resolveFields($bundleDefinition);
$bundleFields = array_diff_key($bundleFields, $baseFields);
$bundleFieldNames = StringHelper::formatPropertyNameList(array_keys($bundleFields), $baseFieldNames);
// Store the resolved bundle fields in the field map.
$fieldMap['bundles'][$bundleKey] = array_filter(array_combine($bundleFieldNames, $bundleFields));
}
return $fieldMap;
}