0

Given I have a module that defines a new field on an entity. How can I delete that data on uninstalling? There is a requirement:

There is data for the field X on entity type Y

which means I cannot delete the data on the hook_uninstall since it cannot be called.

1
  • Your module (when installing) adding a base field or a bundle field?
    – ssibal
    Commented Apr 11, 2017 at 12:43

1 Answer 1

0

This is a known limitation to Drupals Core and this finally gets resolved for Drupal 8.5.x, see this issue: https://www.drupal.org/project/drupal/issues/2282119

But for versions earlier there is an option to workaround this, by creating a form that handles the cleaning of added data to make the uninstall validation pass. This is a UI solution but you still need to add a not somewhere that users know how to find the form. See how the Flag module handled it: https://www.drupal.org/node/2409673

There are other options like creating a drush command, but what you basically need to do is to clean the added data from the database to make the validation for uninstall pass and allow users to uninstall the module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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