Responds to entity DELETE requests.
mixed $id: The entity ID.
\Drupal\rest\ResourceResponse The HTTP response object.
\Symfony\Component\HttpKernel\Exception\HttpException
public function delete($id) {
$definition = $this
->getPluginDefinition();
$entity = entity_load($definition['entity_type'], $id);
if ($entity) {
if (!$entity
->access('delete')) {
throw new AccessDeniedHttpException();
}
try {
$entity
->delete();
watchdog('rest', 'Deleted entity %type with ID %id.', array(
'%type' => $entity
->entityType(),
'%id' => $entity
->id(),
));
// Delete responses have an empty body.
return new ResourceResponse(NULL, 204);
} catch (EntityStorageException $e) {
throw new HttpException(500, t('Internal Server Error'), $e);
}
}
throw new NotFoundHttpException(t('Entity with ID @id not found', array(
'@id' => $id,
)));
}