You are here

public function DomainNegotiator::isRegisteredDomain in Domain Access 8

Checks that a URL's hostname is registered as a valid domain or alias.

Parameters

string $hostname: A string representing the hostname of the request (e.g. example.com).

Return value

bool TRUE if a URL's hostname is registered as a valid domain or alias, or FALSE.

Overrides DomainNegotiatorInterface::isRegisteredDomain

File

domain/src/DomainNegotiator.php, line 200

Class

DomainNegotiator

Namespace

Drupal\domain

Code

public function isRegisteredDomain($hostname) {

  // Direct hostname match always passes.
  if ($domain = $this
    ->domainStorage()
    ->loadByHostname($hostname)) {
    return TRUE;
  }

  // Check for registered alias matches.
  $values = [
    'hostname' => $hostname,
  ];

  /** @var \Drupal\domain\DomainInterface $domain */
  $domain = $this
    ->domainStorage()
    ->create($values);
  $domain
    ->setMatchType(DomainNegotiatorInterface::DOMAIN_MATCHED_NONE);

  // Now check with modules (like Domain Alias) that register alternate
  // lookup systems with the main module.
  $this->moduleHandler
    ->alter('domain_request', $domain);

  // We must have registered a valid id, else the request made no match.
  if (!empty($domain
    ->id())) {
    return TRUE;
  }
  return FALSE;
}