You are here

public function EntityResource::deleteIndividual in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::deleteIndividual()
  2. 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::deleteIndividual()

Deletes an individual entity.

Parameters

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

Return value

\Drupal\jsonapi\ResourceResponse The response.

File

core/modules/jsonapi/src/Controller/EntityResource.php, line 371

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

public function deleteIndividual(EntityInterface $entity) {

  // @todo Replace with entity handlers in: https://www.drupal.org/project/drupal/issues/3230434
  if ($entity
    ->getEntityTypeId() === 'user') {
    $cancel_method = \Drupal::service('config.factory')
      ->get('user.settings')
      ->get('cancel_method');

    // Allow other modules to act.
    user_cancel([], $entity
      ->id(), $cancel_method);

    // Since user_cancel() is not invoked via Form API, batch processing
    // needs to be invoked manually.
    $batch =& batch_get();

    // Mark this batch as non-progressive to bypass the progress bar and
    // redirect.
    $batch['progressive'] = FALSE;
    batch_process();
  }
  else {
    $entity
      ->delete();
  }
  return new ResourceResponse(NULL, 204);
}