Skip to content

002: An environment's value replaces the site's value

Status: accepted, 2026-11-08.

Context

A setting can have a value per environment, like the hostname aliases of a site on local and on the default environment. Three places laid the environment's values over the site's with a deep merge, which appends lists. An environment could not drop an alias the site answers to, and the site plugin applied the environment a second time over definitions that already held it, so aliases appeared twice. The definitions cache is not keyed by environment: drush can build it under another environment than the web server reads it.

Decision

Drupal\sites\SiteSetting\LayerMerge::settings() is the one rule: a scalar replaces, a list replaces as a whole, a keyed map (the language domains) is merged key by key. Site definitions hold the default environment's values and every environment's overrides as stored; the site plugin lays the environment in effect over them once, when it is instantiated.

Consequences

  • An update writes the list each environment showed so far into its own rows, so no environment loses a hostname alias. A removal saved in an environment form before the update never took effect; it has to be saved again.
  • Code that reads a setting with an environment value asks the site plugin, not $definition['settings']. The shield page cache policy reads every environment of the definition, since it runs before the environment is known (sites_shield 1.0.0-beta2 and later).
  • SettingsMergeGuardTest keeps inline deep merges of settings out.

Rejected options

  • Append and deduplicate: keeps the site's aliases on every environment, which is what an environment needs to change.
  • A merge policy per setting key: one more property for every setting plugin, and the same question asked per key.
  • Trusted hosts per environment: the hostname index lists the hostnames of every environment on purpose; request resolution checks the host against the environment in effect.

Reopen when

A setting needs its environment value added to the site's value rather than replacing it.

Last updated 2026-11-08