hook_install() is invoked before the module's default config is installed during config import

Created on 1 September 2017, almost 7 years ago
Updated 13 February 2024, 5 months ago

Problem/Motivation

When my module is enabled I need some content to be created, so I'm using hook_install() to create it. As content belongs to specific entities bundles I'm adding the required config entities in /config/install.

When installing the module in a running instance all works as expected.

However when module is installed through a configuration import process - either from Config UI or drush ci or config_installer profile - the whole import process while installing the module.

The error - in my case - is "Field field_myfieldname is unknown", which is a field on one of the bundles I create instances for in my hook_install().

I can't find any similar issue in the queue, and this makes me nervous because creating-content-on-module-install looks to me like a common scenario. That let me thinks the system may work as expected and the problem here is hook_install() shouldn't be used for creating content.

Proposed resolution

If this is a real bug, investigate and fix the problem. .
If developers shouldn't rely on config/install/* to be available on hook_install(), then this issue should become a Documentation task and we can update the docs about config/install ( Include default configuration in your Drupal 8 module โ†’ & Co.) as well as hook_install() api.

Remaining tasks

  • Confirming if this is a real issue or documentation should be updated
  • Work on a patch

User interface changes

None.

API changes

None(?)

Data model changes

None.

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Configurationย  โ†’

Last updated 20 minutes ago

Created by

๐Ÿ‡ฎ๐Ÿ‡นItaly gambry Milan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024