Question

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.
  \Drupal::service('entity.definition_update_manager')->applyUpdates();

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)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top