You are here

protected function LinkProviderManager::ensureAccess in JSON:API Hypermedia 8

Ensures that access cacheability is captured.

Parameters

\Drupal\Core\Cache\CacheableMetadata|null $cacheability: The access related cacheability to be captured or NULL if there is none.

\Drupal\jsonapi_hypermedia\AccessRestrictedLink $link: The link for which to ensure access cacheability is captured.

Return value

\Drupal\jsonapi\JsonApiResource\Link|null A JSON:API link or NULL if the given link is not accessible.

1 call to LinkProviderManager::ensureAccess()
LinkProviderManager::getLinkCollection in src/Plugin/LinkProviderManager.php
Gets a LinkCollection of 3rd-party links for the given context object.

File

src/Plugin/LinkProviderManager.php, line 136

Class

LinkProviderManager
Manages discovery and instantiation of resourceFieldEnhancer plugins.

Namespace

Drupal\jsonapi_hypermedia\Plugin

Code

protected function ensureAccess(&$cacheability, AccessRestrictedLink $link) {
  if (!$cacheability) {
    $cacheability = new CacheableMetadata();
  }
  $cacheability
    ->addCacheableDependency($link);
  if (!$link
    ->isAllowed()) {
    return NULL;
  }
  return $link
    ->getInnerLink();
}