Last active
June 30, 2021 15:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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