Environment Switchers
This documentation needs review. See "Help improve this page" in the sidebar.
Overview
Environment Switcher links allow users to quickly switch to the same page on a different environment (e.g., from staging to production). They are often placed in the admin toolbar or page top region, depending on the enabled integration.
Some site builders use switcher links as a convenient way to navigate between language versions of a multilingual site.
Configuration
Create or update switchers through Configuration → Development → Environment Indicator Settings → Environment Switcher. (/admin/config/development/environment-indicator/switcher)
Environment switchers are configuration entities and should be managed through Drupal's configuration system. You can also export them for deployment using the configuration staging workflow (e.g., drush config-export).
Creating a Switcher Link Using Drush
To create a switcher link using the command line interface instead of via the user interface, a series of drush config:set commands must be executed. Be sure to use a unique machine name (ID) and uuid for each switcher. Reusing either will result in a configuration error or overwrite an existing switcher.
drush --yes config:set environment_indicator.switcher.production machine 'production'
drush --yes config:set environment_indicator.switcher.production uuid '971430b9-85ed-5yb7-8ef1-0fae13bd3032'
drush --yes config:set environment_indicator.switcher.production name 'Production'
drush --yes config:set environment_indicator.switcher.production url 'https://example.com'
drush --yes config:set environment_indicator.switcher.production fg_color '#000000'
drush --yes config:set environment_indicator.switcher.production bg_color '#3dff24'
drush --yes config:set environment_indicator.switcher.production weight 2
drush --yes config:set environment_indicator.switcher.production langcode 'en'
drush --yes config:set environment_indicator.switcher.production status true
Managing in a Configuration Staging Workflow
-
Use
drush config-export(or the admin UI) to export changes to YAML files underconfig/sync. -
Commit these files to version control and deploy them to other environments using
drush config-importor your CI/CD pipeline.
If you want the list of switcher links to differ across environments (e.g., dev lists staging and prod, but prod does not list dev), you should exclude environment_indicator.switcher.* config entities from your exported config. Instead, manage them per-environment using config_ignore, or by deploying site-specific configuration in config/split or another environment-based method.
This ensures consistent switcher configuration across environments without relying on overrides in settings.php.
Managing Environment-Specific Switchers
If you want the list of switcher links to differ across environments (e.g., dev lists staging and prod, but prod does not list dev), you can handle this with either the Config Ignore or Config Split modules. Each has trade-offs.
Option 1: Config Ignore
Use the Config Ignore module to prevent specific config from being imported on certain environments.
How to use:
-
Add
environment_indicator.switcher.*to the ignore list. -
Maintain switcher entities manually per environment.
Advantages:
-
Simple to set up.
-
No environment-specific folder structure required.
Disadvantages:
-
Risk of config drift between environments. Database overwrites (e.g., cloning from prod to dev) can wipe local changes unless restored manually or via automation.
-
Switcher configuration is not tracked in version control.
Option 2: Config Split
Use the Config Split module to define environment-specific config.
How to use:
-
Create a split for each environment (e.g.,
dev,stage,prod). -
Assign specific
environment_indicator.switcher.*entities to each split. -
Enable only the relevant split on each environment via
settings.php. -
Export config using
drush csex config_split.config_split.[env].
Advantages:
-
Environment-specific switchers are managed in code.
-
Keeps all config exportable and version-controlled.
Disadvantages:
-
Slightly more setup complexity.
-
Requires extra coordination in CI/CD workflows.Values defined in
settings.phptake precedence over UI-managed configuration.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion