May 14 2018
How to prevent configuration sync from overriding settings in Drupal 8?
Drupal 8's configuration system handles configuration in a unified manner. Although the configuration data can be exported to YAML files, Drupal stores the configuration data in the database allowing the configuration to be managed by version control. There are cases, however, when configuration values need to be overridden for specific purposes. But the big drawback is when the overrides creep into the actual configuration when you don't want it to happen.
Worried how you can prevent configuration sync from overriding setting in your Drupal 8 website?
Here's what you can do.
Configuration Synchronization Issue
Configuration management module allows you to manage and keep track of your configurations while also providing the ability to move them to a different environment (local, dev, QA). It provides the consistency and control over your codebase to move your \data around and have a way to deploy to your production.
Primarily, there are two features in Configuration Sync.
With Export, you can export the full archive of your workflow or configuration of your site.
Suppose you accidentally change some configuration and want to revert to the previous version.
In that case, you can Import the previous archive and upload it.
Importing process doesn't revert our configurations. And gives you the option to undo them.
Therefore, there is no restriction to prevent on import and export. Anytime any configuration can be reverted.
Let’s say, you have changed the contact form on your dev site and also on live site. When you export config on dev, contact form config change is exported.
Then you import that changed config from dev to live. The contact form config for the live site has also be changed as dev config settings. What should you do if you don't want this?
Here's when you can use Config Ignore. It helps you to ignore certain configuration when importing.
Config Ignore allows you to specify some config to ignore when importing. This module is a tool that lets you keep the configuration you want, in place, without any changes. It has a dependency on Config Filter module.
How to Use Config Ignore?
- Install the Config Ignore module from Drupal.org. Using Composer is a good practice when installing a Drupal module. You can also use Drush for the same. Or you can even download and install the module manually.
- Here, I am using composer.
Installing Config Ignore with Composer
composer require 'drupal/config_ignore:2.x-dev' (For config ignore)
composer require 'drupal/config_filter:1.x-dev' (For config filter)
- Go to Extend → Enable the module → Configuration → Development → Configuration Synchronization
In the image below you can see one new tab is added as Ignore. Go to that tab to configure.
- In configuration entity name section, you can add configuration details to 'Ignored' while importing.
- User settings can be set to 'Ignore' for public registration options, user registration email settings, and picture support config. You can then save the changes by selection 'save configuration'.
- Other fields that can be added are:
- custom_contact_form. (Will ignore all config entities that start with .contact_message. custom_contact_form. like fields attached to a custom contact form)
- webform.webform.contact (will force import for this configuration, even if ignored by a wildcard)
- user.mail:register_no_approval_required.body (will ignore the body of the no approval required email setting, but will not ignore other user.mail configuration.)
- You must remember not to ignore the core.extension configuration, since it will prevent importing and enabling new modules.
That's it! And you can now get the configuration you want, in place without any feature being overriden.