Skip to content

Commit

Permalink
cset - allow empty array as value (#4781)
Browse files Browse the repository at this point in the history
* cset - allow empty array as value

* CS

* Double =
  • Loading branch information
weitzman committed Jun 21, 2021
1 parent 8f23dc9 commit 89abfb4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Drupal/Commands/config/ConfigCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public function get($config_name, $key = '', $options = ['format' => 'yaml', 'so
* @hidden-options value
* @usage drush config:set system.site page.front '/path/to/page'
* Sets the given URL path as value for the config item with key <info>page.front</info> of <info>system.site</info> config object.
* @usage drush config:set system.site '[]'
* Sets the given key to an empty array.
* @aliases cset,config-set
*/
public function set($config_name, $key, $value = null, $options = ['input-format' => 'string', 'value' => self::REQ])
Expand All @@ -169,14 +171,20 @@ public function set($config_name, $key, $value = null, $options = ['input-format
$data = $this->stdin()->contents();
}


// Special handling for empty array.
if ($data == '[]') {
$data = [];
}

// Now, we parse the value.
switch ($options['input-format']) {
case 'yaml':
$parser = new Parser();
$data = $parser->parse($data, true);
}

if (is_array($data) && $this->io()->confirm(dt('Do you want to update or set multiple keys on !name config.', ['!name' => $config_name]))) {
if (is_array($data) && !empty($data) && $this->io()->confirm(dt('Do you want to update or set multiple keys on !name config.', ['!name' => $config_name]))) {
foreach ($data as $data_key => $value) {
$config->set("$key.$data_key", $value);
}
Expand Down

0 comments on commit 89abfb4

Please sign in to comment.