protected function ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition in JSON:API 8.2
Same name and namespace in other branches
- 8 src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition()
Get relatable resource types from a field definition.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition from which to calculate relatable JSON:API resource types.
\Drupal\jsonapi\ResourceType\ResourceType[] $resource_types: A list of JSON:API resource types.
Return value
\Drupal\jsonapi\ResourceType\ResourceType[] The JSON:API resource types with which the given field may have a relationship.
1 call to ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition()
- ResourceTypeRepository::calculateRelatableResourceTypes in src/
ResourceType/ ResourceTypeRepository.php - Calculates relatable JSON:API resource types for a given resource type.
File
- src/
ResourceType/ ResourceTypeRepository.php, line 386
Class
- ResourceTypeRepository
- Provides a repository of all JSON:API resource types.
Namespace
Drupal\jsonapi\ResourceTypeCode
protected function getRelatableResourceTypesFromFieldDefinition(FieldDefinitionInterface $field_definition, array $resource_types) {
$item_definition = $field_definition
->getItemDefinition();
$entity_type_id = $item_definition
->getSetting('target_type');
$handler_settings = $item_definition
->getSetting('handler_settings');
$has_target_bundles = isset($handler_settings['target_bundles']) && !empty($handler_settings['target_bundles']);
$target_bundles = $has_target_bundles ? $handler_settings['target_bundles'] : $this
->getAllBundlesForEntityType($entity_type_id);
return array_map(function ($target_bundle) use ($entity_type_id, $resource_types) {
foreach ($resource_types as $resource_type) {
if ($resource_type
->getEntityTypeId() === $entity_type_id && $resource_type
->getBundle() === $target_bundle) {
return $resource_type;
}
}
}, $target_bundles);
}