function scheduler_api_test_uninstall in Scheduler 8
Same name and namespace in other branches
- 2.x tests/modules/scheduler_api_test/scheduler_api_test.install \scheduler_api_test_uninstall()
Implements hook_uninstall().
Although not strictly necessary for testing, it is good practice to tidy up module config and content on uninstalling. Plus, when developing this module and enabling it manually as a real module, this code is needed to clean up, otherwise a re-install fails.
File
- tests/
modules/ scheduler_api_test/ scheduler_api_test.install, line 16 - Install and uninstall hooks for the Scheduler API Test module.
Code
function scheduler_api_test_uninstall() {
// Delete any content that may have been created for the custom node type.
$nids_query = \Drupal::database()
->select('node', 'n')
->fields('n', [
'nid',
])
->condition('n.type', [
'scheduler_api_test',
], 'IN')
->execute();
if ($nids = $nids_query
->fetchCol()) {
$storage = \Drupal::entityTypeManager()
->getStorage('node');
$entities = $storage
->loadMultiple($nids);
$storage
->delete($entities);
\Drupal::messenger()
->addMessage(t('@number %type node(s) have been deleted.', [
'@number' => count($nids),
'%type' => 'scheduler_api_test',
]));
}
// The content type, custom fields and storage are deleted automatically by
// having 'enforced: module: - scheduler_api_test' in the
// config/install/*.yml files.
}