You are here

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

Deletes a named variable.

@command acsf-vdel

Parameters

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

Throws

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

\InvalidArgumentException If the argument is missing or invalid.

File

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

Class

AcsfVariablesCommands
Provides drush commands for the acsf_variables module.

Namespace

Drupal\acsf_variables\Commands

Code

public function vdel($name) {
  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 delete as the first argument.'));
  }
  $storage = \Drupal::service('acsf.variable_storage');
  if ($variable = $storage
    ->get($name)) {
    if ($storage
      ->delete($name)) {
      $this
        ->output()
        ->writeln(dt('@name was deleted.', [
        '@name' => $name,
      ]));
    }
    else {
      throw new AcsfException(dt('Unable to delete the @name variable.', [
        '@name' => $name,
      ]));
    }
  }
  else {
    throw new AcsfException(dt('@name not found.', [
      '@name' => $name,
    ]));
  }
}