summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
diff options
context:
space:
mode:
authorAlex Pott2017-04-18 13:12:08 +0100
committerAlex Pott2017-04-18 13:12:08 +0100
commit7cad23ab2a3d3469456de44caff8c0f4d00d664b (patch)
tree3ce0d55a4d64a0984f16953d99d06da10203cbd4 /core/modules/rest/src/Plugin/rest/resource/EntityResource.php
parentcc774252330bf33ca36fceccb85d4f8c03abd340 (diff)
Issue #2848927 by Wim Leers, alexpott: EntityResource::addLinkHeaders() should use LinkRelationType plugin instances rather than definitions
Diffstat (limited to 'core/modules/rest/src/Plugin/rest/resource/EntityResource.php')
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php13
1 files changed, 8 insertions, 5 deletions
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index 9b1d15f..a9e0ff0 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -432,7 +432,10 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
*/
protected function addLinkHeaders(EntityInterface $entity, Response $response) {
foreach ($entity->getEntityType()->getLinkTemplates() as $relation_name => $link_template) {
- if ($definition = $this->linkRelationTypeManager->getDefinition($relation_name, FALSE)) {
+ if ($this->linkRelationTypeManager->hasDefinition($relation_name)) {
+ /** @var \Drupal\Core\Http\LinkRelationTypeInterface $link_relation_type */
+ $link_relation_type = $this->linkRelationTypeManager->createInstance($relation_name);
+
$generator_url = $entity->toUrl($relation_name)
->setAbsolute(TRUE)
->toString(TRUE);
@@ -440,10 +443,10 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
$response->addCacheableDependency($generator_url);
}
$uri = $generator_url->getGeneratedUrl();
- $relationship = $relation_name;
- if (!empty($definition['uri'])) {
- $relationship = $definition['uri'];
- }
+
+ $relationship = $link_relation_type->isRegistered()
+ ? $link_relation_type->getRegisteredName()
+ : $link_relation_type->getExtensionUri();
$link_header = '<' . $uri . '>; rel="' . $relationship . '"';
$response->headers->set('Link', $link_header, FALSE);