You are here

public function AcsfVariablesCommands::vset in Acquia Cloud Site Factory Connector 8.2

Sets a named ACSF variable with an optional group.

@command acsf-vset @option group An optional group name for the variable.

Parameters

string $name: The name of the variable to set.

mixed $value: The value of the variable to set.

array $options: The command options supplied to the executed command.

Throws

\Drupal\acsf\AcsfException If the variable does not exist with the provided name or the acsf_variables module isn't enabled.

\InvalidArgumentException If one or more arguments are missing or invalid.

File

acsf_variables/src/Commands/AcsfVariablesCommands.php, line 81

Class

AcsfVariablesCommands
Provides drush commands for the acsf_variables module.

Namespace

Drupal\acsf_variables\Commands

Code

public function vset($name, $value, array $options = [
  'group' => NULL,
]) {
  if (!\Drupal::moduleHandler()
    ->moduleExists('acsf_variables')) {
    throw new AcsfException(dt('The acsf_variables module must be enabled.'));
  }
  if (empty($name)) {
    throw new \InvalidArgumentException(dt('You must provide the name of the variable to set as the first argument.'));
  }
  if (empty($value)) {
    throw new \InvalidArgumentException(dt('You must provide the value of the variable to set as the second argument.'));
  }
  if (\Drupal::service('acsf.variable_storage')
    ->set($name, $value, $options['group'])) {
    $this
      ->output()
      ->writeln(dt('@name was set to !value', [
      '@name' => $name,
      '!value' => $value,
    ]));
  }
  else {
    throw new AcsfException(dt('The @name variable could not be set.'));
  }
}