3

I'm developing a module in Drupal 8, and because it handles quite a few relations between entities, I always need to add a bit of test data before being able to test the forms for the actual entity I'm working on after a uninstall/reinstall of the module. During install I can add this data in the module.install->xx_install hook. But during uninstall I get the error

"The following reasons prevent the modules from being uninstalled: There is content for the entity type..."

I tried implementing the uninstall hook and truncate the table there, but it seems the check for existing content is done before this hook runs. How can I truncate the necessary tables without having to do it manually? Having to do it manually slows down development quite a bit. Alternatively, is there a way to speed up development of the entity forms and relations so that I don't always have to install/uninstall the module to see changes?

  • Drupal handles schema automatically so you don't have to do anything. – user21641 Mar 10 '16 at 11:12
  • 1
    Yes, but my question is about forcing removal of content from the database before the module is uninstalled. I tried simply adding a field to the entity that I'm working on and refreshing the form page for that entity, but the new field does not show up unless I uninstall/reinstall the module... – Jens Wegar Mar 10 '16 at 12:18
  • Sounds like you're not handling schema properly. There wouldn' be any content to delete since Drupal would drop all your module's tables during uninstallation. – user21641 Mar 10 '16 at 17:08
7

That's a known issue right now.

There's no way right now to hook into that automatically. And it came up a few times already here too. See this question for example: Module uninstall dependencies

Beside a form or a drush command to do the cleanup, there really isn't much that you do right now, other than improving core. What I'd like to see is a message on the uninstall confirmation form that tells you that it will delete all records of entity type N and then does so in a batch before actually uninstalling. See the referenced flag issue in the other question and my repeated suggestions to open an issue, but so far, nobody could be bothered with doing that. And I didn't find time myself either.

Update

Drupal 8.2 now offers a link on the uninstall form to delete all entities of the given type.

  • ok, thanks! I will look into creating a cleanup command that I can run for now. – Jens Wegar Mar 11 '16 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.