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