You are here

EntityDeleteController.php in Delete all 8

Same filename and directory in other branches
  1. 2.x src/Controller/EntityDeleteController.php

File

src/Controller/EntityDeleteController.php
View source
<?php

namespace Drupal\delete_all\Controller;

use Drupal\delete_all\Controller\DeleteControllerBase;

/**
 * Returns responses for devel module routes.
 */
class EntityDeleteController extends DeleteControllerBase {

  /**
   * Get ids of the entities to delete.
   *
   * @param string $entity_type
   *   entity machine name
   *
   * @param string $bundle_type
   *   entity machine name
   *
   * @param array $entity_info
   *   entity definition information
   *
   * @return array
   *   Array of ids of entities to delete.
   */
  public function getEntitiesToDelete($entity_type, $bundle_type = false, $entity_info) {
    $entities_to_delete = [];

    // Delete content by entity type.
    if ($entity_type !== FALSE) {
      $query = \Drupal::entityQuery($entity_type);
      if ($bundle_type) {
        $query
          ->condition($entity_info[$entity_type]['entity_bundle'], $bundle_type);
      }
      $to_delete = $query
        ->execute();
    }
    else {
      $to_delete = [];
    }
    return $to_delete;
  }

  /**
   *
   */
  public function getEntitiesDeleteBatch($entities_to_delete = FALSE, $entity_type) {

    // Define batch.
    $batch = [
      'operations' => [
        [
          'delete_all_entities_batch_delete',
          [
            $entities_to_delete,
            $entity_type,
          ],
        ],
      ],
      'finished' => 'delete_all_entities_batch_delete_finished',
      'title' => $this
        ->t('Deleting entities'),
      'init_message' => $this
        ->t('Entity deletion is starting.'),
      'progress_message' => $this
        ->t('Deleting entities...'),
      'error_message' => $this
        ->t('Entity deletion has encountered an error.'),
    ];
    return $batch;
  }

}

Classes

Namesort descending Description
EntityDeleteController Returns responses for devel module routes.