summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-04-18 13:12:08 +0100
committerAlex Pott2017-04-18 13:12:08 +0100
commit7cad23ab2a3d3469456de44caff8c0f4d00d664b (patch)
tree3ce0d55a4d64a0984f16953d99d06da10203cbd4
parentcc774252330bf33ca36fceccb85d4f8c03abd340 (diff)
Issue #2848927 by Wim Leers, alexpott: EntityResource::addLinkHeaders() should use LinkRelationType plugin instances rather than definitions
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php13
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php10
2 files changed, 13 insertions, 10 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);
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
index 81baf9e..6cd5b6b 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
@@ -424,11 +424,11 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
if ($this->entity->getEntityType()->getLinkTemplates()) {
$this->assertArrayHasKey('Link', $response->getHeaders());
$link_relation_type_manager = $this->container->get('plugin.manager.link_relation_type');
- $expected_link_relation_headers = array_map(function ($rel) use ($link_relation_type_manager) {
- $definition = $link_relation_type_manager->getDefinition($rel, FALSE);
- return (!empty($definition['uri']))
- ? $definition['uri']
- : $rel;
+ $expected_link_relation_headers = array_map(function ($relation_name) use ($link_relation_type_manager) {
+ $link_relation_type = $link_relation_type_manager->createInstance($relation_name);
+ return $link_relation_type->isRegistered()
+ ? $link_relation_type->getRegisteredName()
+ : $link_relation_type->getExtensionUri();
}, array_keys($this->entity->getEntityType()->getLinkTemplates()));
$parse_rel_from_link_header = function ($value) use ($link_relation_type_manager) {
$matches = [];