Skip to content

Instantly share code, notes, and snippets.

@lincoln-chawora
Last active June 30, 2021 15:20
Show Gist options
  • Save lincoln-chawora/067b15b73cf3518e7b0ffa4145f34188 to your computer and use it in GitHub Desktop.
Save lincoln-chawora/067b15b73cf3518e7b0ffa4145f34188 to your computer and use it in GitHub Desktop.
How to delete multiple nodes by ID in Drupal 8 using hook update
/**
* Delete multiple nodes by ID.
*/
function YOU_MODULE_NAME_update_8001() {
$nids = [8418,8419];
/** @var \Drupal\node\NodeStorageInterface $storage */
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
if ($nodes = $storage->loadMultiple($nids)) {
$node_storage->delete($nodes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment