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
    Scrum events

    Blog

    Scrum events

    Scrum defines several events (sometimes called ceremonies) that occur inside each sprint: sprint planning, daily scrum, sprint review, and sprint retrospective.

    Written by Svetoslava Angelova
    Nov 22, 20223 min read
    Scrum artefacts

    Blog

    Scrum artefacts

    In software development, the term “artefact” refers to information that stakeholders and the scrum team use to describe a product that’s being developed.

    Written by Svetoslava Angelova
    Nov 23, 20222 min read
    Headless Drupal with Next.js - simple example walkthrough

    Blog

    Headless Drupal with Next.js - simple example walkthrough

    The trend recently, in web development in general, and consequently in Drupal development is to use the technology headless. The trend recently, in web development in general, and consequently in Drupal development is to use the technology headless.

    Written by Mihail Shahov
    Jan 13, 20237 min read
    Hire dedicated software developers (teams)

    Blog

    Hire dedicated software developers (teams)

    Tired of raising expenses with your in-house development team? Why not get a dedicated team at 40% to 60% of the cost?

    Written by Mihail Shahov
    Jul 17, 20203 min read
    The importance of the right development partner in your software development life cycle

    Blog

    The importance of the right development partner in your software development life cycle

    Unlocking success: The art of choosing the perfect software development partner. Explore the pivotal role of partners in software development, uncover ROI secrets, and stay ahead of industry trends in this must-read article.

    Written by Mihail Shahov
    Sep 26, 20238 min read
    Config split module tutorial for Drupal

    Blog

    Config split module tutorial for Drupal

    Very often we as developers need to work with different environments. This could sometimes lead to (un)expected problems. In Drupal 8 we use the configuration system which works pretty nice, but there are cases where the settings for the local and any other environment should be different.

    Written by Ivaylo Tsandev
    May 20, 20217 min read
    Unveiling the power duo: Next.js as the Headless frontend of Drupal 10

    Blog

    Unveiling the power duo: Next.js as the Headless frontend of Drupal 10

    Discover the dynamic synergy between Drupal 10 and Next.js, as this powerful combination reshapes the landscape of web development. Next.js, an open-source React-based framework, is seamlessly integrated as the headless frontend of Drupal 10, offering a plethora of benefits. From enhanced performance with features like automatic code splitting and server-side rendering to flexible design and SEO-friendly capabilities, this collaboration empowers developers to create high-performing, scalable, and visually appealing web applications. The efficient content management of Drupal 10 coupled with Next.js' adaptability to trends ensures a cutting-edge development approach, positioning this tandem at the forefront of modern web development practices. Embrace the future with the Drupal 10 and Next.js combination, redefining how we approach and craft dynamic online experiences.

    Written by Todor Kolev
    Feb 07, 20245 min read
    How we optimised an SSL overall rating from B to A+

    Blog

    How we optimised an SSL overall rating from B to A+

    Optimising the SSL implementation allows all customers to open and browse the site securely without warnings.

    Written by Mihail Shahov
    Feb 15, 20223 min read

    GET IN TOUCH

    Have a project you'd like to launch?