This module is not useful on its own, and should only be installed if it's required by another module.

Configuration Provider facilitates updating configuration from installed modules.

Configuration Provider provides a plugin type for extension-provided configuration. It includes support for the two core extension types, config/install and config/optional. Contributed modules may provide their own plugins that serve distinct use cases. Modules that have configuration provider plugins include:

Integrating into Configuration Updates

Configuration Provider is used by Configuration Synchronizer.

Background and use case

Drupal core's configuration management system supports two directory types for extension-provided configuration, InstallStorage::CONFIG_INSTALL_DIRECTORY and InstallStorage::CONFIG_OPTIONAL_DIRECTORY, with most relevant code in the ConfigInstaller class.

The structure of the code is suitable for the use case of staging configuration, but has several shortcomings when it comes to other use cases.

  • It's not easy for contributed modules to provide additional configuration providers that meet distinct use cases. Examples of such are the Configuration Share module, which provides a config/share directory, and the Config Actions module, which enables programmatic alteration of configuration through actions provided at config/actions.
  • It's not easy to answer the question: what configuration would be provided if the currently installed modules were reinstalled? For example, the logic to determine what optional configuration will be installed is embedded in ConfigInstaller::installOptionalConfig(), which doesn't just determine what will be installed but installs the configuration. This question is a critical one for solutions like Configuration Synchronizer, which aims to merge configuration updates from updated extensions into the active configuration.

Configuration Provider addresses these use cases by providing a plugin type that modules can use to extend core's built in configuration provision directories. To do so, it extends the ConfigInstaller class via a service alter to provide a custom ::getConfigToInstall() method that passes the request to all available configuration provider plugins. (It's necessary to use a service alter rather than decorating the core service because ::getConfigToInstall is a protected method.) In doing so, it also passes configuration data provided by previous provider plugins, allowing a plugin to accomplish tasks like (a) fulfill configuration entity dependency requirements on demand (as in Configuration Share) or (b) modify configuration prior to it being installed (as in Config Actions Provider).

Tips for developers writing a configuration provider plugin:

  • Have a look at existing implementations, both in Configuration Provider itself - implemented on behalf of Drupal core - and in Configuration Share and Config Actions Provider.
  • Keep in mind that on module install Configuration Provider will scan all installed modules, not just the module being installed, for provided configuration. This approach is by design as it's needed for various use cases like Config Actions Provider (any module may alter config provided by any other module) and core's optional configuration (any module may provide configuration that's dependent on any other module's configuration). It's up to the implementing plugin to limit the configuration it provides or alters in ::getConfigToCreate() and ::addInstallableConfig().

API

Configuration Provider 8.x-2.x provides a storage service, config_provider.storage. The config_provider.collector service provides a method ::addInstallableConfig(), that can be used to populate the config_provider.storage storage with configuration that would be installed if all currently installed extensions (modules, themes, and the install profile) were reinstalled. Sample usage:

$collector = \Drupal::service('config_provider.collector');
// Add installable configuration to the config_provider.storage storage.
$config = $collector->addInstallableConfig();
// Get the service for the storage that contains the installable configuration items.
$provider_storage = \Drupal::service('config_provider.storage');
// List available items.
$item_names = $provider_storage->listAll();

This approach may be used, for example, as part of an update workflow, to determine what updates are available from installed extensions, as is done in Configuration Synchronizer.

The plugin.manager.config_provider.processor service provides a method, ::getDefinitions(), that can be used to load definitions of all available ConfigProvider plugins. Sample usage:

$config_provider_manager = \Drupal::service('plugin.manager.config_provider.processor');
$definitions = $config_provider_manager->getDefinitions();
Supporting organizations: 
Partial sponsorship for 2.x upgrade
Sponsoring development
Drupal 10 compatibility and ongoing maintenance

Project information

Releases