19

In Drupal 8 the Drush command drush variable-set no longer works.

From reading (here) it appears that Drupal 8 has a new "configuration" system that replaces the old (Drupal <=7) "variables". But what is the new Drush command to achieve the same ends?

Specifically I want to convert the commands:

drush variable-set site_mail [email protected] drush variable-set update_notify_emails [email protected] 

to the new Drupal8/Drush8 equivalent...

3 Answers 3

21

Following some more research it seems the new command is:

  • drush config-set <config-name> <key> (where the old format was drush variable-set <name> <value>). Alias: cset.

So I'm not totally sure that I have this right (so comment and/or another answer from someone who does would be great...), but it seems that the config that includes emails are: contact.form.feedback recipients, update.settings notification.emails and system.site mail.

This update is the result for some good discussion (below). Note that some settings are arrays (rather than strings):

www/drupal8# drush config-get update.settings notification 'update.settings:notification': emails: - [email protected] threshold: all 

to update this you need to run:

drush -y config-set update.settings notification.emails.0 [email protected] 

Source: Leverage Drush 7 for Drupal 8.

Note: Drush 7 no longer supports Drupal 8, but this still applies.

6
  • 1
    There's also drush cedit, that allows you to edit the file in an editor. I guess you'd need notification.emails.0 or so to set it to a list, not sure. Commented Jul 2, 2015 at 8:32
  • The changed format may cause your notifications to fail. In the original case email is an array containing [email protected] (i.e. multiple email addresses), but in your result you've turned email into a string containing [email protected] (i.e. single email address). Commented Jul 6, 2015 at 17:32
  • @Alma - Thanks for the heads up. How do I make sure that it get's entered as an array? Commented Jul 7, 2015 at 1:28
  • 1
    Yes. Berdir's solution works. So you'd do "drush config-set update.settings notification.emails.0 [email protected]". Just tested it myself now. Commented Jul 7, 2015 at 15:43
  • 1
    A drush config-list will print every possible category of configuration for you to parse through. In case you are ever in need of finding them all. Commented Aug 8, 2016 at 18:52
6

Additional follow-up,

To find the identifiers for the config to get or set,

  • You can NO LONGER guess at the machine names of variables just by inspecting system settings forms. There used to be a 1:1:1 match between the form element seen on many config screens, the $config['varname'] you could put into $settings.php, and drush vset/vget
  • The config manager in the ui (found at admin/config/development/configuration/single ) provides something of a variable browser.

I wanted to update my local.settings.php to always disable css & js aggregation when downsyncing.

D7 :

$conf['preprocess_css'] = FALSE; $conf['preprocess_js'] = FALSE; 

D8 :

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

(And note that this type of override WILL NOT show up in your Admin UI, or in drush config-get ... though it will take effect)

1
  • Drush command for disabling aggregation then is: drush -y config-set system.performance css.preprocess 0 && drush -y config-set system.performance js.preprocess 0 Commented Aug 1, 2016 at 11:39
5

This worked for me. It's a Drush PHP EVAL command.

drush ev '\Drupal::state()->set("MY_VARIABLE", "MY_VALUE")' 

Here it's being used to set the state of MY_VARIABLE

You can also get the state of a variable:

drush ev 'echo \Drupal::state()->get("MY_VARIABLE")' 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.