Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Drupal 8 Delete entity programmatically

Drupal 8 Delete entity programmatically
, by
Drupal 8 Delete entity programmatically
1 answer
votes: 1366
Answer

To query entities you can use entityQuery, example below uses this.

// Get all users with email containing "xyz"
$query = \Drupal::entityQuery('user')
  ->condition('mail', "XYZ", 'CONTAINS');
$uids = $query->execute();

// Load these entities ($uids) in our case using storage controller.
// We call loadMultiple method and give $uids array as argument.     
$itemsToDelete = \Drupal::entityTypeManager()->getStorage('user')
  ->loadMultiple($uids);

// Loop through our entities and deleting them by calling by delete method.
foreach ($itemsToDelete as $item) {
  $item->delete();
}