You are here

public function DeleteContent::deleteAllEntity in Drush Delete All 8.2

Same name and namespace in other branches
  1. 3.x src/DeleteContent.php \Drupal\drush_delete\DeleteContent::deleteAllEntity()

To delete the entity content.

Parameters

string $type: Entity type.

Return value

string return.

File

src/DeleteContent.php, line 70

Class

DeleteContent

Namespace

Drupal\drush_delete

Code

public function deleteAllEntity($type) {
  $query = \Drupal::entityQuery($type);
  $nids = $query
    ->execute();
  $no_delete = 0;
  if (!empty($nids)) {
    foreach ($nids as $nid) {
      $delete = \Drupal::entityTypeManager()
        ->getStorage($type)
        ->load($nid)
        ->delete();
      $no_delete++;
    }
    return $no_delete . " no of contents are deleted";
  }
  else {
    return "Content not found !";
  }
}