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

Breadcrumb

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

function 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);
}
RSS feed
Powered by Drupal