3

This article explains that using $conf in settings.php works differently in Drupal 8 compared to Drupal 7:

The settings.php file could contain environment level overrides. Just remember how we disabled email sending on development servers in Drupal 7:

$conf['mail_system']['default-system'] = 'DevelMailLog';

That’s how it will look in Drupal 8:

$config['system.mail']['interface']['default'] = 'devel_mail_log';

In Drupal 7, I used $conf to set different Google Analytics accounts per site environment like this:

  if (PANTHEON_ENVIRONMENT == 'dev') {
    // Google Analytics.
    $conf['googleanalytics_account'] = 'UA-XXXXXXXX-X';
  }
  else if (PANTHEON_ENVIRONMENT == 'test') {
    // Google Analytics.
    $conf['googleanalytics_account'] = 'UA-XXXXXXXX-Y';
  }
  else if (PANTHEON_ENVIRONMENT == 'live') {
    // Google Analytics.
    $conf['googleanalytics_account'] = 'UA-XXXXXXXX-Z';
  }

How can I determine what $conf['googleanalytics_account'] was renamed to in Drupal 8?

4

Unless the module's documentation tells you the name directly, you'll have to look for it manually.

You can search with drush:

drush config-list (cli)     List config names

Choose one of the names and display its whole content:

drush config-get (cget)     Display a config value, or a whole configuration object.

If you are using a lot of modules, that list may grow fast so you can narrow it down by inspecting the module to get an idea of how its data is structured.

Drupal 8 modules can ship with documentation in a .yml file in their config/install directory, which may include default values for configuration. It seems unlikely there would be a hardcoded default value for the equivalent of the googleanalytics_account variable, but you would at least be able to find the code fetching its value, something like this: \Drupal::config('googleanalytics.account');. *

There's also the new State API, meant to store information which could be different depending on the environment (dev vs production), or any other information you would not want to synchronize with different instances of the same system, like the last time automated jobs ran. If the module uses that, look instead for lines like this: \Drupal::state()->get('googleanalytics_account'). *

Once you've found what you think may be the correct key name, you can retrieve its current value using drush:

drush state-get key
  • The names used here are quick guesses based on the Drupal 7 names, the real code may use entirely different names.
  • Perfect! For those looking for the google analytics variable: $config['google_analytics.settings']['account'] = 'UA-123456'; – Patrick Kenny Jan 30 '16 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.