Skip to content

Instantly share code, notes, and snippets.

@sumanthkumarc
Last active August 19, 2016 05:53
Show Gist options
  • Save sumanthkumarc/a2e390e9e79c99c0465a315b0fa34350 to your computer and use it in GitHub Desktop.
Save sumanthkumarc/a2e390e9e79c99c0465a315b0fa34350 to your computer and use it in GitHub Desktop.
simple configuration api usage Druapl 8(D8)
# Taken from :https://www.drupal.org/developing/api/8/configuration/simple
//Immutable Config (Read Only)
$config = \Drupal::config('system.performance');
//Mutable Config (Read / Write)
$config = \Drupal::service('config.factory')->getEditable('system.performance');
// To read contents
$message = \Drupal::config('system.maintenance')->get('message'); //gets only particular key value, or array if data in next levels
$message = \Drupal::config('system.maintenance')->get(); // gets all config as array
// To Write data, first get mutable object, then write and then save. Config must be saved explicitly
// Set a scalar value.
$config->set('cache.page.enabled', 1);
// Set an array of values.
$page_cache_data = array('enabled' => 1, 'max_age' => 5);
$config->set('cache.page', $page_cache_data);
// Save your data to the file system.
$config->save();
// To clear, should be saved after clear
$config->clear(cache.page.enabled')->save();
// To delete entire set, donot save after delete
$config->delete(cache.page')->delete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment