Back to blogs

How to Config Split

Submitted on: May 8 2024

A quick summary of when we need config split:

Config split module is useful when we need some modules for development or testing but we don't want them in live (or any other environment), with this module we are allow to configure sub config folders that will be loaded just when we allow them to be loaded in the settings.php.

Basic config steps

  • Install the latest config split version for the Drupal version you have, can be found here:
  • https://www.drupal.org/project/config_split
  • Enable the module with drush en config_split
  • Go to module config with this route /admin/config/development/configuration/config-split this route may change but you can always go to the extend page and search the module, in there you'll see the configuration link.
  • On the config split configuration page you'll see a page with all the configured splits, in our case that its a newly install module we won't have any. If we click on "Add Configuration Split setting" button we'll get the configuration for a new config split. 
  • In there we can fill the following fields:
    • Label: Put a descriptive label so you don't get confuse on what its in that split.
    • Description: Write a quick description of what will be store in that config split
    • Storage: We have 3 options here Folder, Collection, Database, we don't need to change the default that is folder unless we need a very specific config that requires the others.
    • Folder: Where the config split will be saved, try to save it under a folder with a similar name as the label.
    • Status: This control whenever a split will load or not, by default true but with this we can do the magic in settings.php to conditionally load the splits.
    • Complete split: This let us remove an entire config from the default config and put it in our split.
    • Partial split: Let us add a patch to add/remove config after the default config ran (for example core.extension let us enable/disable modules).
  • Once we fill the needed fields we can save that split.
  • Now if we run drush cex to get the config split out.
  • Then if we want to load this split conditionally we can add this code to the settings.php:

    if ([ContitionsToNotLoad]) {  
    	$config['config_split.config_split.test']['status'] = FALSE; 
    }