protected function EntityResource::getBaseRoute in Drupal 10
Same name and namespace in other branches
- 8 core/modules/rest/src/Plugin/rest/resource/EntityResource.php \Drupal\rest\Plugin\rest\resource\EntityResource::getBaseRoute()
- 9 core/modules/rest/src/Plugin/rest/resource/EntityResource.php \Drupal\rest\Plugin\rest\resource\EntityResource::getBaseRoute()
Gets the base route for a particular method.
Parameters
string $canonical_path: The canonical path for the resource.
string $method: The HTTP method to be used for the route.
Return value
\Symfony\Component\Routing\Route The created base route.
Overrides ResourceBase::getBaseRoute
File
- core/
modules/ rest/ src/ Plugin/ rest/ resource/ EntityResource.php, line 367
Class
- EntityResource
- Represents entities as resources.
Namespace
Drupal\rest\Plugin\rest\resourceCode
protected function getBaseRoute($canonical_path, $method) {
$route = parent::getBaseRoute($canonical_path, $method);
switch ($method) {
case 'GET':
$route
->setRequirement('_entity_access', $this->entityType
->id() . '.view');
break;
case 'POST':
$route
->setRequirement('_entity_create_any_access', $this->entityType
->id());
$route
->setOption('_ignore_create_bundle_access', TRUE);
break;
case 'PATCH':
$route
->setRequirement('_entity_access', $this->entityType
->id() . '.update');
break;
case 'DELETE':
$route
->setRequirement('_entity_access', $this->entityType
->id() . '.delete');
break;
}
$definition = $this
->getPluginDefinition();
$parameters = $route
->getOption('parameters') ?: [];
$parameters[$definition['entity_type']]['type'] = 'entity:' . $definition['entity_type'];
$route
->setOption('parameters', $parameters);
return $route;
}