function EntityResource::deleteIndividual

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::deleteIndividual()
  2. 10 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::deleteIndividual()
  3. 11.x 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.