function lightning_test_uninstall in Lightning Core 8
Same name and namespace in other branches
- 8.2 modules/lightning_test/lightning_test.install \lightning_test_uninstall()
Implements hook_uninstall().
File
- modules/
lightning_test/ lightning_test.install, line 107 - Contains installation routines for Lightning Test.
Code
function lightning_test_uninstall() {
$state = \Drupal::state();
// Delete all content entities created while the module was installed.
$delete = $state
->get('_delete', []);
foreach ($delete as $entity_type => $entities) {
$storage = \Drupal::entityTypeManager()
->getStorage($entity_type);
$entities = $storage
->loadMultiple($entities);
$storage
->delete($entities);
}
$state
->delete('_delete');
// Delete all fields created while the module was installed. The most stable
// way to do this is to execute the entity form which deletes a field.
$fields = $state
->get('_fields', []);
if ($fields) {
$form = \Drupal::entityTypeManager()
->getFormObject('field_config', 'delete');
$fields = FieldConfig::loadMultiple($fields);
foreach ($fields as $field) {
$form_state = new FormState();
\Drupal::formBuilder()
->submitForm($form
->setEntity($field), $form_state);
}
}
$state
->delete('_fields');
}