public function EntityResource::delete

Responds to entity DELETE requests.

Parameters

mixed $id: The entity ID.

Return value

\Drupal\rest\ResourceResponse The HTTP response object.

Throws

\Symfony\Component\HttpKernel\Exception\HttpException

File

drupal/core/modules/rest/lib/Drupal/rest/Plugin/rest/resource/EntityResource.php, line 60
Definition of Drupal\rest\Plugin\rest\resource\EntityResource.

Class

EntityResource
Represents entities as resources.

Namespace

Drupal\rest\Plugin\rest\resource

Code

public function delete($id) {
  $definition = $this
    ->getDefinition();
  $entity = entity_load($definition['entity_type'], $id);
  if ($entity) {
    try {
      $entity
        ->delete();

      // Delete responses have an empty body.
      return new ResourceResponse(NULL, 204);
    } catch (EntityStorageException $e) {
      throw new HttpException(500, 'Internal Server Error', $e);
    }
  }
  throw new NotFoundHttpException(t('Entity with ID @id not found', array(
    '@id' => $id,
  )));
}