Drupal 8 Configuration : Get, Set and Override | Drupal 8

Drupal 8 Configuration : Get, Set and Override

Submitted by editor on Thu, 11/02/2017 - 19:26
Question

How to get (check) drupal configuration value ?
How to set drupal configuration value ?
How to Override drupal configuration value from setting.php file ?

Get, Set and Delete configuration value by drush

Get (drush config-get)

drush cget CONFIG_NAME CONFIG_KEY
Examples:
drush cget system.site
drush cget system.site page.front

Set (drush config-set)

drush cset CONFIG_NAME CONFIG_KEY CONFIG_VALUE
Example:
drush config-set system.site page.front node

Delete (drush config-delete)

drush cdel CONFIG_NAME
Example
drush cget mymodule.test

Export config to files (drush config-export)

drush cex -y

Import Config from files (drush config-import)

drush cim -y

 

 

Configuration override from Settings.php

You can override configuration from settings.php files.

Examples :
- Disable CSS/JS compress on local / development envirenement.
$config['system.performance']['css']['preprocess'] = 0;
$config['system.performance']['js']['preprocess'] = 0;

Link : https://www.drupal.org/docs/8/api/configuration-api/configuration-override-system

Comments

Ashwin Parmar (not verified)

Fri, 12/15/2017 - 04:52

I have one custom module with config data.

mymodule
-- config/mymodule.yml

--

mymodule.yml
apikey: xxxxx
apisecret: xxxxx

Now, I have install this module.

After, I want to add one more config key in YML file. For that drupal suggest, first uinstall module, add new key in configuration file, reinstall module.

After, cache clear it will work.

Question: is there any other alternative, so I shouldn't uninstall mymodule?

Thanks

Add new comment