X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Frest%2Fsrc%2FPathProcessor%2FPathProcessorEntityResourceBC.php;fp=web%2Fcore%2Fmodules%2Frest%2Fsrc%2FPathProcessor%2FPathProcessorEntityResourceBC.php;h=1f68691a2b72844f723ce4416fb689c03e40ffb6;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/rest/src/PathProcessor/PathProcessorEntityResourceBC.php b/web/core/modules/rest/src/PathProcessor/PathProcessorEntityResourceBC.php new file mode 100644 index 000000000..1f68691a2 --- /dev/null +++ b/web/core/modules/rest/src/PathProcessor/PathProcessorEntityResourceBC.php @@ -0,0 +1,55 @@ +entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public function processInbound($path, Request $request) { + if ($request->getMethod() === 'POST' && strpos($path, '/entity/') === 0) { + $parts = explode('/', $path); + $entity_type_id = array_pop($parts); + + // Until Drupal 8.3, no entity types specified a link template for the + // 'create' link relation type. As of Drupal 8.3, all core content entity + // types provide this link relation type. This inbound path processor + // provides automatic backwards compatibility: it allows both the old + // default from \Drupal\rest\Plugin\rest\resource\EntityResource, i.e. + // "/entity/{entity_type}" and the link template specified in a particular + // entity type. The former is rewritten to the latter + // specific one if it exists. + $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); + if ($entity_type->hasLinkTemplate('create')) { + return $entity_type->getLinkTemplate('create'); + } + } + return $path; + } + +}