You are here

function _drush_no_autocomplete_set_options in No Autocomplete 7

Same name and namespace in other branches
  1. 8 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 the values from the config.
  $config_status = variable_get($variable, FALSE);
  $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' ? array(
      1,
      dt('activated'),
    ) : array(
      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.', array(
        '@status' => $status,
        '@option_text' => $option_text,
      ));
      drush_log($message, 'warning');
      return;
    }

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