You are here

public function DomainCommands::defaultDomain in Domain Access 8

Sets the default domain.

@option validate Force a check of the URL response before allowing registration. @usage drush domain-default www.example.com @usage drush domain-default example_org @usage drush domain-default www.example.org --validate=1

@command domain:default @aliases domain-default

Parameters

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

array $options: An associative array of options whose values come from cli, aliases, config, etc.

Return value

string The machine name of the default domain.

Throws

\Drupal\domain\Commands\DomainCommandException

File

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

Class

DomainCommands
Drush commands for the domain module.

Namespace

Drupal\domain\Commands

Code

public function defaultDomain($domain_id, array $options = [
  'validate' => NULL,
]) {

  // Resolve the domain.
  if (!empty($domain_id) && ($domain = $this
    ->getDomainFromArgument($domain_id))) {
    $validate = $options['validate'] ? 1 : 0;
    $domain
      ->addProperty('validate_url', $validate);
    if ($error = $this
      ->checkHttpResponse($domain)) {
      throw new DomainCommandException(dt('Unable to verify domain !domain: !error', [
        '!domain' => $domain
          ->getHostname(),
        '!error' => $error,
      ]));
    }
    else {
      $domain
        ->saveDefault();
    }
  }

  // Now, ask for the current default, so we know if it worked.
  $domain = $this
    ->domainStorage()
    ->loadDefaultDomain();
  if ($domain
    ->status()) {
    $this
      ->logger()
      ->info(dt('!domain set to primary domain.', [
      '!domain' => $domain
        ->getHostname(),
    ]));
  }
  else {
    $this
      ->logger()
      ->warning(dt('!domain set to primary domain, but is also inactive.', [
      '!domain' => $domain
        ->getHostname(),
    ]));
  }
  return $domain
    ->id();
}