You are here

public function ResourceObjectSchemaLinkProvider::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/ResourceObjectSchemaLinkProvider.php, line 31

Class

ResourceObjectSchemaLinkProvider
Class ResourceObjectSchemaLinkProvider.

Namespace

Drupal\jsonapi_schema\Plugin\jsonapi_hypermedia\LinkProvider

Code

public function getLink($context) {
  assert($context instanceof ResourceObject);
  $resource_type_name = $context
    ->getResourceType()
    ->getTypeName();
  $resource_schema_uri = Url::fromRoute("jsonapi_schema.{$resource_type_name}.type");
  return AccessRestrictedLink::createLink(AccessResult::allowed(), new CacheableMetadata(), $resource_schema_uri, $this
    ->getLinkRelationType());
}