Created
October 19, 2018 17:39
-
-
Save DanLaufer/0bdb58ede6ab4d2e7cb78640874404da to your computer and use it in GitHub Desktop.
Drupal 8 - Remove all content of type on module uninstall
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
/** | |
* @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