You are here

public function DomainCommands::scheme in Domain Access 8

Changes a domain scheme.

@usage drush domain-scheme example.com http @usage drush domain-scheme example_com https

@command domain:scheme @aliases domain-scheme

Parameters

string $domain_id: The machine name or hostname of the domain to change.

string $scheme: The scheme to use for the domain: http, https, or variable.

Return value

string The message to print.

Throws

\Drupal\domain\Commands\DomainCommandException

File

domain/src/Commands/DomainCommands.php, line 773

Class

DomainCommands
Drush commands for the domain module.

Namespace

Drupal\domain\Commands

Code

public function scheme($domain_id, $scheme = NULL) {
  $new_scheme = NULL;

  // Resolve the domain.
  if ($domain = $this
    ->getDomainFromArgument($domain_id)) {
    if (!empty($scheme)) {

      // Set with a value.
      $new_scheme = $scheme;
    }
    else {

      // Prompt for selection.
      $new_scheme = $this
        ->io()
        ->choice(dt('Select the default http scheme:'), [
        'http' => 'http',
        'https' => 'https',
        'variable' => 'variable',
      ]);
    }

    // If we were asked to change scheme, validate the value and do so.
    if (!empty($new_scheme)) {
      switch ($new_scheme) {
        case 'http':
          $new_scheme = 'http';
          break;
        case 'https':
          $new_scheme = 'https';
          break;
        case 'variable':
          $new_scheme = 'variable';
          break;
        default:
          throw new DomainCommandException(dt('Scheme name "!scheme" not known.', [
            '!scheme' => $new_scheme,
          ]));
      }
      $domain
        ->saveProperty('scheme', $new_scheme);
    }

    // Return the (new | current) scheme for this domain.
    return dt('Scheme is now to "!scheme." for !domain', [
      '!scheme' => $domain
        ->get('scheme'),
      '!domain' => $domain
        ->id(),
    ]);
  }

  // We couldn't find the domain, so fail.
  throw new DomainCommandException(dt('Domain name "!domain" not known.', [
    '!domain' => $domain_id,
  ]));
}