protected static function buildLinkCollectionFromEntityReferenceField(ResourceObject
$context, EntityReferenceFieldItemListInterface
$field, LinkCollection
$links) { $context_resource_type =
$context->
getResourceType();
$public_field_name =
$context_resource_type->
getPublicName($field->
getName());
if ($context_resource_type->
isLocatable() && !
$context_resource_type->
isInternal()) { $context_is_versionable =
$context_resource_type->
isVersionable();
if (!
$links->
hasLinkWithKey('self'
)) { $route_name = Routes::
getRouteName($context_resource_type, "
$public_field_name.relationship.get"
);
$self_link = Url::
fromRoute($route_name,
['entity' =>
$context->
getId()]);
if ($context_is_versionable) { $self_link->
setOption('query',
[JsonApiSpec::VERSION_QUERY_PARAMETER =>
$context->
getVersionIdentifier()]);
} $links =
$links->
withLink('self',
new Link(new CacheableMetadata(),
$self_link, 'self'
));
} $has_non_internal_resource_type =
array_reduce($context_resource_type->
getRelatableResourceTypesByField($public_field_name),
function D
$carry, ResourceType
$target) { return $carry ?: !
$target->
isInternal();
}, FALSE
);
// If a `related` link was not provided, automatically generate one from
// the relationship object to the collection resource with all of the
// resources targeted by this relationship. However, that link should
// *not* be generated if all of the relatable resources are internal.
// That's because, in that case, a route will not exist for it.