protected function ResourceTypeRepository::calculateRelatableResourceTypes in JSON:API 8
Same name and namespace in other branches
- 8.2 src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::calculateRelatableResourceTypes()
Calculates relatable JSON API resource types for a given resource type.
This method has no affect after being called once.
Parameters
\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The resource type repository.
Return value
array The relatable JSON API resource types, keyed by field name.
1 call to ResourceTypeRepository::calculateRelatableResourceTypes()
- ResourceTypeRepository::all in src/
ResourceType/ ResourceTypeRepository.php - Gets all JSON API resource types.
File
- src/
ResourceType/ ResourceTypeRepository.php, line 189
Class
- ResourceTypeRepository
- Provides a repository of all JSON API resource types.
Namespace
Drupal\jsonapi\ResourceTypeCode
protected function calculateRelatableResourceTypes(ResourceType $resource_type) {
// For now, only fieldable entity types may contain relationships.
$entity_type = $this->entityTypeManager
->getDefinition($resource_type
->getEntityTypeId());
if ($entity_type
->entityClassImplements(FieldableEntityInterface::class)) {
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($resource_type
->getEntityTypeId(), $resource_type
->getBundle());
return array_map(function ($field_definition) {
return $this
->getRelatableResourceTypesFromFieldDefinition($field_definition);
}, array_filter($field_definitions, function ($field_definition) {
return $this
->isReferenceFieldDefinition($field_definition);
}));
}
return [];
}