public function TopLevelSchemaLinkProviderBase::getLink in JSON:API Schema 8
Adds, alters or removes hyperlinks from a link collection.
Parameters
\Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel|\Drupal\jsonapi\JsonApiResource\ResourceObject|\Drupal\jsonapi\JsonApiResource\Relationship $context: The context object from which links should be generated.
Return value
\Drupal\jsonapi_hypermedia\AccessRestrictedLink A link to be added to the context object. An AccessRestrictedLink should be returned if the link target may be inaccessible to some users.
Overrides LinkProviderInterface::getLink
File
- src/
Plugin/ jsonapi_hypermedia/ LinkProvider/ TopLevelSchemaLinkProviderBase.php, line 56
Class
- TopLevelSchemaLinkProviderBase
- Class TopLevelSchemaLinkProviderBase.
Namespace
Drupal\jsonapi_schema\Plugin\jsonapi_hypermedia\LinkProviderCode
public function getLink($context) {
assert($context instanceof JsonApiDocumentTopLevel);
if (static::$schemaRouteType === 'entrypoint') {
$schema_route_name = "jsonapi_schema." . static::$schemaRouteType;
}
else {
$route = $this->currentRouteMatch
->getRouteObject();
assert($route instanceof Route);
$resource_type = $route
->getDefault(Routes::RESOURCE_TYPE_KEY);
if (!$resource_type instanceof ResourceType) {
return AccessRestrictedLink::createInaccessibleLink(new CacheableMetadata());
}
$schema_route_name = "jsonapi_schema.{$resource_type->getTypeName()}." . static::$schemaRouteType;
}
return AccessRestrictedLink::createLink(AccessResult::allowed(), new CacheableMetadata(), new Url($schema_route_name), $this
->getLinkRelationType());
}