You are here

public function EntityResource::delete in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rest/src/Plugin/rest/resource/EntityResource.php \Drupal\rest\Plugin\rest\resource\EntityResource::delete()
  2. 9 core/modules/rest/src/Plugin/rest/resource/EntityResource.php \Drupal\rest\Plugin\rest\resource\EntityResource::delete()

Responds to entity DELETE requests.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

Return value

\Drupal\rest\ModifiedResourceResponse The HTTP response object.

Throws

\Symfony\Component\HttpKernel\Exception\HttpException

File

core/modules/rest/src/Plugin/rest/resource/EntityResource.php, line 324

Class

EntityResource
Represents entities as resources.

Namespace

Drupal\rest\Plugin\rest\resource

Code

public function delete(EntityInterface $entity) {
  try {
    $entity
      ->delete();
    $this->logger
      ->notice('Deleted entity %type with ID %id.', [
      '%type' => $entity
        ->getEntityTypeId(),
      '%id' => $entity
        ->id(),
    ]);

    // DELETE responses have an empty body.
    return new ModifiedResourceResponse(NULL, 204);
  } catch (EntityStorageException $e) {
    throw new HttpException(500, 'Internal Server Error', $e);
  }
}