Share this article:

Blog
Jul 27, 20217 min read

Config ignore module tutorial for Drupal

Config ignore module tutorial for Drupal

In the previous tutorial, we spoke about the Config Split module for Drupal 8. Today I'm gonna show you another configuration-related module for Drupal 8/9 – Config Ignore. They are partially overlapping with each other. Both of them help us keep configurations among different environments separate. However, the usage is slightly different. So is the result. The best way to learn and understand it is by using real-life examples.

Let's say we need to make some development related to the sending mail functionality. We may want to style a template. Or make an event subscriber where we want to send a specific mail to the site admin. Or make some notification on a cron execution. Or just make sure we can send emails at all!

Let's use the site's default email for this example. So in the local environment, we would most likely use our own email, right? But when we export the configurations for the testing or the live environment, we don't want our email to be set as the default one, but instead, we'd want this to be the real email. So, we need to ignore this configuration. Can we do that?

Sure we can! Curious already? Let's get started!

We need to first install and enable the Config Ignore module:

composer require drupal/config_ignore
drush en config_ignore
 

Let's also clear the cache

drush cache:rebuild

and we'd have the module up and running already. It has a dependency on another module – Config Filter, but it is handled automatically for us. We just have to approve enabling both modules if needed. This module works closer to the core's configuration system, so it is not so obvious by first sight where it takes place. We don't have any new entries in the main Configuration → Development area. Let's see what do we have there.

Configuration ignore synchronization
As mentioned already – nothing special. Just the default configuration synchronisation system, provided by the core which we usually use to import and export our configurations. When we execute these actions via the drush commands [config:import] and [config:export], we basically trigger the same actions we would see here. But let's see what's inside.

Configuration ignore tab

OK, now here we already have another tab beside the standard ones. This is the ‘Ignore’ tab where we need to work. Let's see what it looks like.

Configuration ignore tab page

It's pretty simple. Just a form where we could place our configurations which we want to be ignored. The people who created it even describe how to use it. Thanks, guys! I won't duplicate the examples we have there, but instead, focus on our specific use case. We need our email to be only used for local development. The next things we'd need are:

  • when we export the configurations, our email should not be exported among them
  • when we import the configurations, we don't want the real email from the testing or the live environment for our development purposes, so we don't want our configuration overwritten.

Config Ignore to the rescue! We have few ways of describing the configurations. But first, let's export the initial configurations in order to be able to see the difference later on:

drush config:export

Note: Please, do not perform the following step yet. I am doing it here only for explanation reasons.

I went into the Configuration → System → Basic site settings, changed the email there with my own one, and saved it. Now when we go back to the configuration synchronisation part (Configuration → Development → Configuration Synchronisation), we see a change in the system.site.yml file and we may check it by pressing View differences.

Config ignore view differences

Let's now add the configuration string from the image below in the ‘Ignore’ tab and press the ‘Save configuration’ button.

Config ignore settings

But now, when we export again, we'd see both changes – the one in system.site and the other in the config_ignore.settings. And we don't want that. We need just the second one. The reason we see them both now is that the config system doesn't know yet it has to ignore the system.site one. So what would be better to do is to first add the record in the Ignore area, export, then change the email and save. OK, then let's do it right this time.

We visit the Ignore tab and add one of the following:

- system.site → Note this would ignore the entire ‘Basic site settings’ page.

- system.site:mail → This would only ignore the email part of the setting. Noticed the colon before the mail? This is how we set only a specific key from a configuration file to be ignored. Let's go with this one now. This time, we should have the following:

Config ignore settings

We are ready to export via:

drush config:export

so we make sure that the email will be ignored next time we change it. This time we only see the change in ‘config_ignore.settings’. This is what we expect. Let's now go and change that email already. After that, let's see what does the ‘Synchronise’ tab show us.

Config synchronization

The system is smart enough to see the difference, but ignore it and even let us know it has been ignored already. Now we only see there is a change, but we don't have the button to view it. We are now ready to change that email value as much as we like. It is important to say that since we only ignored the mail, any other change in the system.site would be handled as a real change by the system, i.e. it wouldn't be ignored unless we put the entire system.site in the Ignore area or any other of its keys in the same way we did with the mail. Every new record should be placed on a new line. This is how the Config Ignore module works.

I'm sure you already noticed this, but let me point it out only for completeness reasons. This configuration should be now set up with its real value on every different environment, meaning that you would still need to update the mails in the testing, live, or any other environments. It won't be replaced with either importing or exporting actions.

That would work with every configuration, even if it's a custom one we defined ourselves. Just keep in mind that ignoring a new configuration would leave it empty, even if it has a value on the local environment. Exporting it however would generate the yml file so it would be available everywhere.

This is a brief tutorial for the Config Ignore module usage. We might also point out some differences between it and the Config Split module. They both have their strengths. So how do we choose which one to use? Well, this depends on the use case we have, but let's see their specifications:

  • Config Ignore – simpler to use, closer to the core functionality. Adding another configuration for ignoring is as simple as just putting it into the form. However one needs to take care of the same configuration in each environment. If there are just a few records added, this is not a real issue though.
  • Config Split – more powerful, provides the option to define all possible environments in advance. It allows us to predefine the configurations we want per each environment and forget about them once imported. There is also an option to configure an entire module being enabled or disabled per environment much easier. However, it is slightly more difficult to set up and use.

At the end of the day, it's really a matter of preference.

I hope you find this tutorial useful!

SUBSCRIBE TO OUR NEWSLETTER

Share this article:

SUBSCRIBE TO OUR NEWSLETTER

Related Blog Articles

    Why startups hesitate to work with a bespoke software development agency – and how we address every concern

    Blog

    Why startups hesitate to work with a bespoke software development agency – and how we address every concern

    Startups often hesitate to work with software agencies due to concerns over cost, control, and flexibility. Discover how Bulcode’s bespoke software solutions address each challenge, ensuring growth and agility.

    Written by Svetoslava Angelova
    Nov 05, 20245 min read
    Building a high-performing Agile team: Our proven approach

    Blog

    Building a high-performing Agile team: Our proven approach

    Discover how we build high-performing Agile teams by defining clear roles, fostering collaboration, and using flexible tools.

    Written by Svetoslava Angelova
    Aug 27, 20248 min read
    Drupal 11: What to expect? Comprehensive guide to new features and enhancements

    Blog

    Drupal 11: What to expect? Comprehensive guide to new features and enhancements

    Drupal 11 is out! In this article, discover it's exciting features and improvements. Upgrade now to redefine your digital strategy with Bulcode's expert support.

    Written by Svetoslava Angelova
    Aug 05, 20247 min read
    Single Directory Components in Drupal core: A comprehensive overview

    Blog

    Single Directory Components in Drupal core: A comprehensive overview

    Explore how Single Directory Components (SDC) in Drupal Core streamline the development process by encapsulating component-related files into a single directory. Learn about the benefits of SDCs and follow a step-by-step guide to implement them in your Drupal projects.

    Written by Nikolay Tsekov
    Aug 07, 20244 min read
    Drupal 9 convert image to WebP format

    Blog

    Drupal 9 convert image to WebP format

    WebP is able to take data compression to a new level thanks to the inclusion of a prediction mode to the JPG process, making it clear to see how it can outperform its JPG-based relative. And we have the results to prove it.

    Written by Vasil Boychev
    Apr 06, 20228 min read
    React overview - Definition, SPA, Components, Hooks

    Blog

    React overview - Definition, SPA, Components, Hooks

    React is a free and open-source front-end JavaScript framework for creating user interfaces based on UI components. It is also known as React.js or ReactJS.

    Written by Mihail Shahov
    May 13, 20226 min read
    What is Agile and why we use it?

    Blog

    What is Agile and why we use it?

    Agile is a time-boxed, iterative method to software delivery that aims to provide software gradually throughout the project rather than all at once near the end.

    Written by Svetoslava Angelova
    Sep 15, 20225 min read
    NVM vs NPM vs Yarn

    Blog

    NVM vs NPM vs Yarn

    Compared to the three technologies, NVM differs from the other two. Node Version Manager (NVM) is used to manage Node.js versions. NPM and Yarn are Node.js package managers. They allow downloading, installing, and managing packages when developing in JavaScript.

    Written by Ventsislav Venkov
    Sep 15, 20225 min read
    Which IT engagement model is right for you?

    Blog

    Which IT engagement model is right for you?

    Fixed price, time and materials, or dedicated teams? Consider carefully all the pros and cons of the engagement model for your project.

    Written by Svetoslava Angelova
    Sep 26, 202210 min read
    Varna and Burgas airports' websites use React components in Drupal

    Blog

    Varna and Burgas airports' websites use React components in Drupal

    Drupal is a modular system whose functions can be adapted to many different requirements, which is particularly important for public administration projects.

    Written by Mihail Shahov
    Nov 04, 20224 min read
    Laravel Mix - a simple and powerful wrapper around Webpack

    Blog

    Laravel Mix - a simple and powerful wrapper around Webpack

    Laravel Mix provides a fluent API for defining webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors.

    Written by Stefani Tashkova
    Nov 15, 20224 min read
    What is Scrum?

    Blog

    What is Scrum?

    Scrum is a part of the Agile methodology. It is the most popular framework for agile development, and it is a simple process framework.

    Written by Svetoslava Angelova
    Nov 20, 20224 min read

    GET IN TOUCH

    Have a project you'd like to launch?