hook_install() may not work as intended, if modules installed in bulk

Created on 23 June 2025, 5 days ago

Problem/Motivation

Prior to Drupal 11.2, when we install multiple modules at once, each of them would go through the regular steps of hook_install() and config install, before the next module is installed.
This means that, if module B depends on module A, then in B_install() it can pick up and alter configuration that module B introduced in B/config/optional.

Since Drupal 11.2., this is no longer the case.
If A and B are installed in bulk, then B_install() will fire _before_ the config from A/config/optional is present.
If A and B are installed one after the other, then B_install() will fire _after_ the config from A/config/optional is present.

This can be mitigated by setting 'container_rebuild_required' on one of the two modules.
But do we really want this?

Steps to reproduce

Create module A with config/optional/views.view.a.yml
Create module B with B_install() which loads 'views.view.a' and adds some fields to it.

Proposed resolution

We could detect if modules have a hook_install(), and if so, put them in separate groups.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

extension system

Created by

πŸ‡©πŸ‡ͺGermany donquixote

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

Comments & Activities

  • Issue created by @donquixote
  • πŸ‡©πŸ‡ͺGermany donquixote

    Here is a list of commits for ModuleInstaller since 11.1.8.

    * 4837c52b Issue #3497105 by quietone, borisson_: Fix LineLength for inline comments
    * 101e0606 Issue #3496558 by alexpott, godotislate: Install entity definitions for all modules in batch install before simple config
    * 6e7715a8 Issue #3492282 by nicxvan, longwave, catch: Refactor away ModuleInstaller::invokeAll()
    * 59ce5ede Issue #3494212 by godotislate, alexpott, larowlan: Modules that provide fields for entities of other modules can't be installed
    * 57583222 Issue #3487154 by quietone, daffie, smustgrave: Fix Drupal.Commenting.FunctionComment.MissingReturnComment in core/lib/Drupal/Core/A-E
    * 58be5f12 Issue #3492235 by catch, longwave, mikelutz: Default container_rebuild_required to FALSE
    * 16967de8 Issue #3492705 by catch, nicxvan, mikelutz, longwave: Install modules with container_rebuild_true set by themselves
    * f8090e61 Issue #3416522 by catch, alexpott, longwave, phenaproxima, nicxvan, wim leers, smustgrave, larowlan, berdir, godotislate, dww: Add the ability to install multiple modules and only do a single container rebuild to ModuleInstaller
    * eab46c49 Issue #3486995 by nicxvan: Clean up how ModuleInstaller invokes hooks around installing other modules
    * 76323d65 Issue #3490296 by nicxvan: Mark hook_install_tasks and hook_install_tasks_alter as procedural only
    * 2c9e1fa9 Issue #3486462 by nicxvan: Support #Hook for several hooks called by ModuleInstaller

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I'm wondering if it's worth considering a new hook: hook_post_install_optional

    https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

    I think this type of config was never really meant to be handled in hook install but worked.

    I think adding a new hook might give a place to interact with this config safely.

  • πŸ‡©πŸ‡ͺGermany donquixote

    I think this type of config was never really meant to be handled in hook install but worked.

    I don't think the creators of this hook had any preference whether or not people use it to alter configuration from config/optional from another module.

    I'm wondering if it's worth considering a new hook: hook_post_install_optional

    To me it seems like a clear regression.
    We should fix core, rather than asking people to change their code.

Production build 0.71.5 2024