You are here

public static function AccessRestrictedLink::createInaccessibleLink in JSON:API Hypermedia 8

Creates an AccessRestricted link that will not be displayed.

Use this when the link should *not* be present in the response. This is not always about access control, but it can be. For example, take a link provider that generates a "publish" link, it may be executed for a resource object that is already published. In that case, following the link might cause a client error. The link provider should return an inaccessible link to prevent the client from making a bad request. In another case, the current user might not have sufficient permissions to publish the resource object; this is also a valid reason for creating an inaccessible link.

Parameters

\Drupal\Core\Cache\CacheableDependencyInterface $access_cacheability: The link access cacheability. This is typically an access result related to whether the current user is able to follow the link or not.

Return value

\Drupal\jsonapi_hypermedia\AccessRestrictedLink A new link object.

File

src/AccessRestrictedLink.php, line 129

Class

AccessRestrictedLink
Decorates a JSON:API link to consider link accessibility.

Namespace

Drupal\jsonapi_hypermedia

Code

public static function createInaccessibleLink(CacheableDependencyInterface $access_cacheability) {
  return new static(AccessResult::forbidden()
    ->addCacheableDependency($access_cacheability));
}