Change record status: 
Project: 
Introduced in branch: 
8.9.x
Introduced in version: 
8.9.0-alpha1
Description: 

Prior to 8.9.0, module authors needed to check the config installer to see if config was being synced when their hook_install, hook_uninstall, hook_modules_installed and hook_modules_uninstalled was being called.

To make it easier to check the config installer syncing status, an $is_syncing parameter is now passed to these hooks.

The value of $is_syncing will be TRUE when a module is being installed/uninstalled as part of a configuration import. In these cases, your hook implementation needs to carefully consider what changes, if any, it should make. For example, it should not make any changes to configuration objects or entities.

e.g. from demo_umami_content module

Before

/**
 * Implements hook_install().
 */
function demo_umami_content_install() {
  if (!\Drupal::service('config.installer')->isSyncing()) {
    \Drupal::classResolver(InstallHelper::class)->importContent();
  }
}

After

/**
 * Implements hook_install().
 */
function demo_umami_content_install($is_syncing) {
  if (!$is_syncing) {
    \Drupal::classResolver(InstallHelper::class)->importContent();
  }
}
Impacts: 
Module developers
Distribution developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

pingwin4eg’s picture

For example, it should not make any changes to configuration objects or entities.

Are there alternative ways to change configs and entities? For example, if there's a need to add fields to an entity type and fill them with values during a module install.

In a website development it's a usual thing that new custom modules are installed in all envs except local through the configuration import.