public function DomainNegotiator::setRequestDomain in Domain Access 8
Determines the active domain request.
The negotiator is passed an httpHost value, which is checked against domain records for a match.
Parameters
string $httpHost: A string representing the hostname of the request (e.g. example.com).
bool $reset: Indicates whether to reset the internal cache.
Overrides DomainNegotiatorInterface::setRequestDomain
1 call to DomainNegotiator::setRequestDomain()
- DomainNegotiator::negotiateActiveDomain in domain/
src/ DomainNegotiator.php - Determine the active domain.
File
- domain/
src/ DomainNegotiator.php, line 100
Class
Namespace
Drupal\domainCode
public function setRequestDomain($httpHost, $reset = FALSE) {
// @TODO: Investigate caching methods.
$this
->setHttpHost($httpHost);
// Try to load a direct match.
if ($domain = $this
->domainStorage()
->loadByHostname($httpHost)) {
// If the load worked, set an exact match flag for the hook.
$domain
->setMatchType(DomainNegotiatorInterface::DOMAIN_MATCHED_EXACT);
}
else {
$values = [
'hostname' => $httpHost,
];
/** @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())) {
$this
->setActiveDomain($domain);
}
elseif ($domain = $this
->domainStorage()
->loadDefaultDomain()) {
$this->moduleHandler
->alter('domain_request', $domain);
$domain
->setMatchType(DomainNegotiatorInterface::DOMAIN_MATCHED_NONE);
if (!empty($domain
->id())) {
$this
->setActiveDomain($domain);
}
}
}