diff --git a/src/EventSubscriber/RedirectRequestSubscriber.php b/src/EventSubscriber/RedirectRequestSubscriber.php index 3ca8b8b..8a49194 100644 --- a/src/EventSubscriber/RedirectRequestSubscriber.php +++ b/src/EventSubscriber/RedirectRequestSubscriber.php @@ -73,6 +73,13 @@ class RedirectRequestSubscriber implements EventSubscriberInterface { protected $pathProcessor; /** + * Domain redirect configuration. + * + * @var \Drupal\Core\Config\Config + */ + protected $domainConfig; + + /** * Constructs a \Drupal\redirect\EventSubscriber\RedirectRequestSubscriber object. * * @param \Drupal\redirect\RedirectRepository $redirect_repository @@ -96,6 +103,7 @@ class RedirectRequestSubscriber implements EventSubscriberInterface { $this->redirectRepository = $redirect_repository; $this->languageManager = $language_manager; $this->config = $config->get('redirect.settings'); + $this->domainConfig = $config->get('redirect.domain'); $this->aliasManager = $alias_manager; $this->moduleHandler = $module_handler; $this->entityManager = $entity_manager; @@ -123,28 +131,31 @@ class RedirectRequestSubscriber implements EventSubscriberInterface { return; } - // Redirect between domains. - $from_domain = $request->getUri(); - $domains = \Drupal::config('redirect.domain')->get('domain_redirects'); - $to_domain = NULL; - // Removes HTTP prefix. - if (strpos($from_domain, 'http://') !== FALSE) { - $from_domain = substr($from_domain, 7); - } - if (strpos($from_domain, 'https://') !== FALSE) { - $from_domain = substr($from_domain, 8); - } - // Checks if there is a redirect domain in the configuration. - foreach ($domains as $domain) { - if ($domain['from'] == $from_domain) { - $to_domain = $domain['to']; - break; + // Redirect between domains configuration. + if ($this->domainConfig) { + $domains = $this->domainConfig->get('domain.redirects'); + + $from_domain = $request->getUri(); + $to_domain = NULL; + // Removes HTTP prefix. + if (strpos($from_domain, 'http://') !== FALSE) { + $from_domain = substr($from_domain, 7); + } + if (strpos($from_domain, 'https://') !== FALSE) { + $from_domain = substr($from_domain, 8); + } + // Checks if there is a redirect domain in the configuration. + foreach ($domains as $domain) { + if ($domain['from'] == $from_domain) { + $to_domain = $domain['to']; + break; + } + } + if ($to_domain) { + $response = new TrustedRedirectResponse($to_domain); + $event->setResponse($response); + return; } - } - if ($to_domain) { - $response = new TrustedRedirectResponse($to_domain); - $event->setResponse($response); - return; } // Get URL info and process it to be used for hash generation.