I've added a field via hook_entity_base_field_info()
. It has data stored in it. I then go to uninstall my module and I get the following error:
-> drush8 pm-uninstall massing -y
The following extensions will be uninstalled: massing
Do you really want to continue? (y/n): y
exception 'Drupal\Core\Extension\ModuleUninstallValidatorException' with message 'The following reasons prevents the modules from being uninstalled: [error]
There is data for the field massing_memberships on entity type User' in
/Users/les.peabody/Sites/drupal8/core/lib/Drupal/Core/Extension/ModuleInstaller.php:347
Stack trace:
#0 /Users/les.peabody/Sites/drupal8/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(95):
Drupal\Core\Extension\ModuleInstaller->uninstall(Array, true)
#1 /Users/les.peabody/opt/drush8/commands/core/drupal/environment.inc(227): Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall(Array)
#2 /Users/les.peabody/opt/drush8/commands/core/drupal/pm_8.inc(80): drush_module_uninstall(Array)
#3 /Users/les.peabody/opt/drush8/commands/pm/pm.drush.inc(1190): _drush_pm_uninstall(Array)
#4 [internal function]: drush_pm_uninstall('massing')
#5 /Users/les.peabody/opt/drush8/includes/command.inc(364): call_user_func_array('drush_pm_uninst...', Array)
#6 /Users/les.peabody/opt/drush8/includes/command.inc(215): _drush_invoke_hooks(Array, Array)
#7 [internal function]: drush_command('massing')
#8 /Users/les.peabody/opt/drush8/includes/command.inc(183): call_user_func_array('drush_command', Array)
#9 /Users/les.peabody/opt/drush8/lib/Drush/Boot/BaseBoot.php(62): drush_dispatch(Array)
#10 /Users/les.peabody/opt/drush8/drush.php(70): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#11 /Users/les.peabody/opt/drush8/drush.php(11): drush_main()
#12 {main}
So what I'm trying to figure out how to do is how to drop the data in this table after I've called for an uninstall on the module, but before the check happens for whether or not there is data in the table. I've tried implementing hook_uninstall()
and hook_module_preuninstall()
but neither of these hooks are invoked before the check for data presence. Thoughts?
EDIT: Looking at ModuleInstaller.php at line 343 (D8 RC1), it runs uninstall validators prior to triggering hook_module_preuninstall
and hook_uninstall
. This is where it is failing. So, maybe there is a way to add an uninstall validator for my module and run it first? There doesn't look to be any other way to do it besides adding some kind of mechanism to the module which makes it "purge" itself of any data it's added to the system, which then lets you uninstall it. Seems terribly convoluted and not side builder friendly in the slightest, very frustrating.