Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

In this post, I'll show you how to override a configuration dynamically in Drupal 8.

You can override configuration from settings.php files using the variable $config.


$config['system.maintenance']['message'] = 'Sorry, our site is down now.';

For nested values, use nested array keys

$config['system.performance']['css']['preprocess'] = 0;

Example of Overriding Payment Gateway configuration for security reasons:

$config['commerce_payment.commerce_payment_gateway.paypal_express_checkout']['configuration'] = [
    'api_username' => 'MY_API_USERNAME',
    'api_password' => 'MY_API_PASSWORD',
    'signature' => 'MY_SIGNATURE',

When using $config override outside of settings.php, use a preceding global $config;

To get the original values without override just use:
$message = \Drupal::config('system.maintenance')->getOriginal('message', FALSE);

To get the override values just use:

method 1

$message = \Drupal::config('system.maintenance')->get('message');

method 2

$message = \Drupal::configFactory()->getEditable('system.maintenance')->get('message');


Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon