You are here

protected function ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition()

Get relatable resource types from a field definition.

The field definition from which to calculate relatable 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 218

Class

ResourceTypeRepository
Provides a repository of all JSON API resource types.

Namespace

Drupal\jsonapi\ResourceType

Code

protected function getRelatableResourceTypesFromFieldDefinition(FieldDefinitionInterface $field_definition) {
  $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) {
    return $this
      ->get($entity_type_id, $target_bundle);
  }, $target_bundles);
}