You are here

function hook_domain_request_alter in Domain Access 8

Allows modules to modify the inbound domain request.

When using this hook, first check $domain->getMatchType(), which returns a numeric constant indicating the type of match derived by the caller or by earlier returns of this hook (such as domain_alias_request_alter()). Use this value to determine if the request needs to be overridden. Valid types are DomainNegotiator::DOMAIN_MATCH_NONE, DomainNegotiator::DOMAIN_MATCH_EXACT, DomainNegotiator::DOMAIN_MATCH_ALIAS.

To issue a redirect, as in the case of Domain Alias, set a redirect property to a valid response code (301 or 302).

Parameters

\Drupal\domain\DomainInterface $domain: A domain object defined by Drupal\domain\DomainInterface.

3 functions implement hook_domain_request_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

domain_alias_domain_request_alter in domain_alias/domain_alias.module
Implements hook_domain_request_alter().
domain_config_test_domain_request_alter in domain_config/tests/modules/domain_config_test/domain_config_test.module
Implements hook_domain_request_alter().
domain_test_domain_request_alter in domain/tests/modules/domain_test/domain_test.module
Implements hook_domain_request_alter().
3 invocations of hook_domain_request_alter()
DomainConfigAlterHookTest::testHookDomainRequestAlter in domain_config/tests/src/Functional/DomainConfigAlterHookTest.php
Tests domain request alteration.
DomainNegotiator::isRegisteredDomain in domain/src/DomainNegotiator.php
Checks that a URL's hostname is registered as a valid domain or alias.
DomainNegotiator::setRequestDomain in domain/src/DomainNegotiator.php
Determines the active domain request.

File

domain/domain.api.php, line 41
API documentation file for Domain module.

Code

function hook_domain_request_alter(\Drupal\domain\DomainInterface &$domain) {

  // Add a special case to the example domain.
  if ($domain
    ->getMatchType() == \Drupal\domain\DomainNegotiatorInterface::DOMAIN_MATCHED_EXACT && $domain
    ->id() == 'example_com') {

    // Do something here.
    $domain
      ->addProperty('foo', 'Bar');
  }
}