Skip to content

Instantly share code, notes, and snippets.

@woutersf
Last active March 12, 2017 08:18
Show Gist options
  • Save woutersf/a304fb2d4bf44143e002da45ffc2cfc5 to your computer and use it in GitHub Desktop.
Save woutersf/a304fb2d4bf44143e002da45ffc2cfc5 to your computer and use it in GitHub Desktop.
Drupal8 settings and config, override settings in settings.php, variable_get en variable_set
<?php
// Fetching The data via the container (old variable_get)
$data = \Drupal::config('my_module.settings')->get('my_setting_name');
// Fetching the data via the Settings class
use Drupal\Core\Site\Settings;
$settings = Settings::get('http_client_config');
$data = $settings['my_setting_name'];
// Old variable_set saving the configuration
\Drupal::configFactory()->getEditable('my_module.settings')->set('my_setting_name', $new_val)->save();
// Override the setting in the settings.php file
$config['my_module.settings']['my_setting_name'] = "The data";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment