summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
diff options
context:
space:
mode:
authorAlex Pott2017-03-27 09:30:26 +0100
committerAlex Pott2017-03-27 09:30:26 +0100
commit0edd07b2f9e0eca6d7b775fa8b233ece7c306464 (patch)
treeec509550b7566cd8debfbceaa4825396a84cf11e /core/modules/rest/src/Plugin/rest/resource/EntityResource.php
parent48261599246bb9369e79ae4ec4b11de6de01e5b8 (diff)
Issue #2853211 by vaplas, Wim Leers, arshadcn: EntityResource::post() incorrectly assumes that every entity type has a canonical URL
Diffstat (limited to 'core/modules/rest/src/Plugin/rest/resource/EntityResource.php')
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index a4162b5..9b1d15f 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -189,8 +189,12 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
// 201 Created responses return the newly created entity in the response
// body. These responses are not cacheable, so we add no cacheability
// metadata here.
- $url = $entity->urlInfo('canonical', ['absolute' => TRUE])->toString(TRUE);
- return new ModifiedResourceResponse($entity, 201, ['Location' => $url->getGeneratedUrl()]);
+ $headers = [];
+ if (in_array('canonical', $entity->uriRelationships(), TRUE)) {
+ $url = $entity->urlInfo('canonical', ['absolute' => TRUE])->toString(TRUE);
+ $headers['Location'] = $url->getGeneratedUrl();
+ }
+ return new ModifiedResourceResponse($entity, 201, $headers);
}
catch (EntityStorageException $e) {
throw new HttpException(500, 'Internal Server Error', $e);