protected function DomainCommands::createDomain in Domain Access 8
Helper function: check a domain is responsive and create it.
Parameters
\Drupal\domain\DomainInterface $domain: The (as yet unsaved) domain to create.
bool $check_response: Indicates that registration should not be allowed unless the server returns a 200 response.
Return value
bool TRUE or FALSE indicating success of the action.
Throws
\Drupal\domain\Commands\DomainCommandException
1 call to DomainCommands::createDomain()
- DomainCommands::add in domain/
src/ Commands/ DomainCommands.php  - Add a new domain to the site.
 
File
- domain/
src/ Commands/ DomainCommands.php, line 1080  
Class
- DomainCommands
 - Drush commands for the domain module.
 
Namespace
Drupal\domain\CommandsCode
protected function createDomain(DomainInterface $domain, $check_response = FALSE) {
  if ($check_response) {
    $valid = $this
      ->checkHttpResponse($domain, TRUE);
    if (!$valid) {
      throw new DomainCommandException(dt('The server did not return a 200 response for !d. Domain creation failed. Remove the --validate flag to save this domain.', [
        '!d' => $domain
          ->getHostname(),
      ]));
    }
  }
  else {
    try {
      $domain
        ->save();
    } catch (EntityStorageException $e) {
      throw new DomainCommandException('Unable to save domain', $e);
    }
    if ($domain
      ->getDomainId()) {
      $this
        ->logger()
        ->info(dt('Created @name at @domain.', [
        '@name' => $domain
          ->label(),
        '@domain' => $domain
          ->getHostname(),
      ]));
      return TRUE;
    }
    else {
      $this
        ->logger()
        ->error(dt('The request could not be completed.'));
    }
  }
  return FALSE;
}