You are here

function _drush_no_autocomplete_set_options in No Autocomplete 8

Same name and namespace in other branches
  1. 7 no_autocomplete.drush.inc \_drush_no_autocomplete_set_options()

Set the variable options.

Parameters

string $variable: The variable name.

string $args: The functions arguments.

1 call to _drush_no_autocomplete_set_options()
drush_no_autocomplete_na_login in ./no_autocomplete.drush.inc
Callback for the na-login command.

File

./no_autocomplete.drush.inc, line 102
Drush commands related to the No Autocomplete module.

Code

function _drush_no_autocomplete_set_options($variable, $args) {

  // Getting an editable config because we will get and set a value.
  $config = \Drupal::service('config.factory')
    ->getEditable('no_autocomplete.settings');

  // Getting the values from the config.
  $config_status = $config
    ->get($variable);
  $status = $config_status ? sprintf(NO_AUTOCOMPLETE_GREEN_OUTPUT, dt('Activated')) : sprintf(NO_AUTOCOMPLETE_RED_OUTPUT, dt('Disabled'));
  switch ($variable) {
    case 'no_autocomplete_login_form':
      $option_text = dt('login form');
      break;
  }
  if (isset($args[0])) {
    list($value, $status) = $args[0] == 'on' ? [
      1,
      dt('activated'),
    ] : [
      0,
      dt('disabled'),
    ];

    // Checking if the status is already configured.
    $already_configured = FALSE;
    if ($config_status && $value) {
      $already_configured = TRUE;
    }
    if (!$config_status && !$value) {
      $already_configured = TRUE;
    }
    if ($already_configured) {
      $message = dt('The "autocomplete=off" option on the user @option_text is already @status.', [
        '@status' => $status,
        '@option_text' => $option_text,
      ]);
      drush_log($message, 'warning');
      return;
    }

    // Saving the values in the config.
    $config
      ->set($variable, $value);
    $config
      ->save();
    $message = dt('You have @status the use of the "autocomplete=off" option on the user @option_text.', [
      '@status' => $status,
      '@option_text' => $option_text,
    ]);
    drush_log($message, 'success');
  }
  else {
    $message = dt('The "autocomplete=off" option on the user @option_text is: @status.', [
      '@status' => $status,
      '@option_text' => $option_text,
    ]);
    drush_print($message);
  }
}