By Jonathan1055


2019-03-09 19:30:37 8 Comments

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)

1 comments

@4k4 2019-03-10 10:28:37

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.

@Jonathan1055 2019-03-10 10:45:01

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.

@4k4 2019-03-10 11:16:23

OK, then you could add a warning that fields added to a content type should be removed by the admin before uninstalling the module.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] load a class in hook_install

  • 2015-09-08 11:38:10
  • Ahmad
  • 177 View
  • -1 Score
  • 1 Answer
  • Tags:   8 installing

1 Answered Questions

[SOLVED] Grant permission for custom role from hook_install programmatically

4 Answered Questions

[SOLVED] How to get hook_install() to run all hook_update_N()?

  • 2011-06-15 09:21:41
  • Lucy
  • 6797 View
  • 18 Score
  • 4 Answer
  • Tags:   6 hooks installing

1 Answered Questions

[SOLVED] Is hook_boot() deprecated?

  • 2017-07-20 09:15:21
  • Amit Kumar
  • 131 View
  • -1 Score
  • 1 Answer
  • Tags:   hooks

2 Answered Questions

[SOLVED] How to uninstall a module that has added a basefield that has data

1 Answered Questions

[SOLVED] How do I change the type of a field attached to a content entity?

0 Answered Questions

Mass insert on hook_install()

  • 2015-07-22 14:12:11
  • MariusP
  • 94 View
  • 1 Score
  • 0 Answer
  • Tags:   installing

1 Answered Questions

[SOLVED] Install other modules from hook_install

1 Answered Questions

[SOLVED] How do you handle long runtime updates needed in hook_install()?

1 Answered Questions

[SOLVED] Can't drupal_execute('filter_admin_format_form') on hook_install?

  • 2012-03-20 14:12:34
  • DanH
  • 159 View
  • 0 Score
  • 1 Answer
  • Tags:   6 installing

Sponsored Content