class PathProcessorEntityResourceBC
Path processor to maintain BC for entity REST resource URLs from Drupal 8.0.
Hierarchy
- class \Drupal\rest\PathProcessor\PathProcessorEntityResourceBC implements \Drupal\Core\PathProcessor\InboundPathProcessorInterface
Expanded class hierarchy of PathProcessorEntityResourceBC
1 string reference to 'PathProcessorEntityResourceBC'
- rest.services.yml in core/
modules/ rest/ rest.services.yml - core/modules/rest/rest.services.yml
1 service uses PathProcessorEntityResourceBC
File
-
core/
modules/ rest/ src/ PathProcessor/ PathProcessorEntityResourceBC.php, line 12
Namespace
Drupal\rest\PathProcessorView source
class PathProcessorEntityResourceBC implements InboundPathProcessorInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Creates a new PathProcessorEntityResourceBC instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->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;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
PathProcessorEntityResourceBC::$entityTypeManager | protected | property | The entity type manager. | |
PathProcessorEntityResourceBC::processInbound | public | function | Processes the inbound path. | Overrides InboundPathProcessorInterface::processInbound |
PathProcessorEntityResourceBC::__construct | public | function | Creates a new PathProcessorEntityResourceBC instance. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.