public function LinkProviderManager::getLinkCollection in JSON:API Hypermedia 8
Gets a LinkCollection of 3rd-party links for the given context object.
Parameters
\Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel|\Drupal\jsonapi\JsonApiResource\ResourceObject|\Drupal\jsonapi\JsonApiResource\Relationship $context: The link context object.
Return value
\Drupal\jsonapi\JsonApiResource\LinkCollection The link collection.
Overrides LinkProviderManagerInterface::getLinkCollection
File
- src/
Plugin/ LinkProviderManager.php, line 111
Class
- LinkProviderManager
- Manages discovery and instantiation of resourceFieldEnhancer plugins.
Namespace
Drupal\jsonapi_hypermedia\PluginCode
public function getLinkCollection($context) {
$definitions = $this
->getApplicableDefinitions($context);
$providers = array_map(function ($plugin_id) use ($definitions) {
return $this
->createInstance($plugin_id, $definitions[$plugin_id]['default_configuration'] ?? []);
}, array_keys($definitions));
$cacheability = NULL;
$link_collection = array_reduce($providers, function (LinkCollection $link_collection, LinkProviderInterface $provider) use ($context, &$cacheability) {
$link = $this
->ensureAccess($cacheability, $provider
->getLink($context));
return $link ? $link_collection
->withLink($provider
->getLinkKey(), $this
->getValidatedLink($link)) : $link_collection;
}, new LinkCollection([]));
$this
->bubbleAccessCacheability($cacheability);
return $link_collection
->withContext($context);
}