Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityResource.php

function 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 326

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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal