function ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition
Same name in other branches
- 9 core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition()
- 10 core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition()
- 11.x core/modules/jsonapi/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 core/
modules/ jsonapi/ src/ ResourceType/ ResourceTypeRepository.php - Calculates relatable JSON:API resource types for a given resource type.
File
-
core/
modules/ jsonapi/ src/ ResourceType/ ResourceTypeRepository.php, line 461
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) {
$type_name = "{$entity_type_id}--{$target_bundle}";
return isset($resource_types[$type_name]) ? $resource_types[$type_name] : NULL;
}, $target_bundles);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.