I maintain a contrib module which defines two base fields, but these are not added to any content type on installation, as this is done during admin config. The module has

// Add our base fields to the schema.

in it's hook_install() and hook_uninstall().
Now that this function is deprecated in core 8.7 I've tried removing the lines and installing, and it seems to work OK.

So can it be OK to simply remove the calls to applyUpdates() ?
I think there were problems with fields not being deleted in the early days of Drupal 8, but maybe it all works better now.

For info, the change record is https://www.drupal.org/node/3034742

Edit: Config inspector is only partially helpful. The fields show up only after saving the content type form display. After uninstall the fields are still shown, but I think this was the case anyway (there is a Core issue relating to this)


The change record you've linked is about update hooks for already installed modules, not hook_install().

You've never needed applyUpdates() in an install hook. If your custom module is adding a new field, it will be added automatically when the module is enabled, and removed when the module is uninstalled. There was only an issue with base fields containing data, but this is resolved since Drupal 8.5. See this change record: Base fields with existing data can now be uninstalled.

| improve this answer | |
  • Thanks 4k4 I was hoping that this was the case. I suspect that when we first starting converting from 7.x to 8.x there were some problems with the fields. But yes I agree that the change record only talks about hook_update. But that was the page given in the deprecation error message so I was working from that. There is also the open core issue drupal.org/project/drupal/issues/2924256 which does affect fields left over after uninstall. – Jonathan1055 Mar 10 '19 at 10:45
  • OK, then you could add a warning that fields added to a content type should be removed by the admin before uninstalling the module. – 4k4 Mar 10 '19 at 11:16

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.