In Drupal 7, we could override the $conf
variables in settings.php to force a site (e.g. development) in maintenance mode. In Drupal 8, this has changed to $config
, but the maintenance mode variable is not part of the configuration anymore. How can I force system.maintenance_mode in a specific environment's configuration?
1 Answer
I think you might want to take a different approach.
The maintenance mode is now a state in Drupal 8, not a configuration. The difference is a state is a ephemeral state that's specific to the current environment (see the state API docs for more info).
As such, you might want to replace the State
service with your own service class that uses the StateInterface
interface if you're looking to fundamentally alter the way state behavior (which could lead to unforeseen problems).
Another tact might involve some sort one-time toggling of state (e.g. programmatically as shown above, a drush state-set
/ drupal state:override
) based on some event (e.g. deployment of site).
-
Thanks for the suggestions. A one time toggle during deployment is an alternative but it does not enforce maintenance mode at all times... for instance someone with proper privileges could turn off maintenance mode in the interface. As Shawn Conn mentions, replacing the State service seems a bit risky. I've updated the question title to better reflect what I'm trying to achieve.– bohemierMar 2, 2017 at 15:11
\Drupal::state()->set('system.maintenance_mode', TRUE);
but there doesn't seem to be a direct way to override state from settings.php