Programmatically delete nodes in Drupal 8

You, DrupalPHP
Back
$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
$entities = $storage_handler->loadMultiple($result);
$storage_handler->delete($entities);

First load the storage handler using the entity type manager object in Drupal 8 and then we need to load the full node before we delete it, loadMultiple() method will help us with that, then we can call storage handler delete method to delete the node and all the hooks associate with it will invoke to reach into the delete operation of the node.

© Heshan Wanigasooriya.RSS

🍪 This site does not track you.