Skip to content

Instantly share code, notes, and snippets.

@DanLaufer
Created October 19, 2018 17:39
Show Gist options
  • Save DanLaufer/0bdb58ede6ab4d2e7cb78640874404da to your computer and use it in GitHub Desktop.
Save DanLaufer/0bdb58ede6ab4d2e7cb78640874404da to your computer and use it in GitHub Desktop.
Drupal 8 - Remove all content of type on module uninstall
/**
* @file
* Install, update and uninstall functions for the sports_system module.
*/
/**
* Implements hook_uninstall().
*/
function sports_system_uninstall() {
$storage = \Drupal::entityManager()->getStorage('node');
$query = \Drupal::entityQuery('node');
$query->condition('type', 'player');
$result = $query->execute();
if (!empty($result)) {
$ids = array_values($result);
$entities = $storage->loadMultiple($ids);
$storage->delete($entities);
}
\Drupal::cache('data')->deleteAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment