You are here

public function DomainLangConfigRedirect::checkRequest in Domain Lang 8

Check current request and redirect if needed.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: Current request response event.

File

src/EventSubscriber/DomainLangConfigRedirect.php, line 55

Class

DomainLangConfigRedirect
Redirect subscriber for control language detection and selection pages.

Namespace

Drupal\domain_lang\EventSubscriber

Code

public function checkRequest(GetResponseEvent $event) {
  $domain = $this->domainNegotiator
    ->getActiveDomain();
  if ($domain instanceof DomainInterface) {
    switch ($event
      ->getRequest()
      ->get(RouteObjectInterface::ROUTE_NAME)) {
      case 'language.negotiation':
        $this->messenger
          ->addStatus($this
          ->t('You was redirected to current active domain language settings page.'));
        $this->messenger
          ->addStatus($this
          ->t('This page should be used for currently active domain language detection and selection setup.'));
        $this
          ->setRedirectResponse($event, 'domain_lang.admin', $domain);
        break;
      case 'language.negotiation_session':
        $args = [
          '@type' => $this
            ->t('Session language detection configuration'),
        ];
        $this->messenger
          ->addStatus($this
          ->t('You was redirected to current active domain @type page.', $args));
        $this->messenger
          ->addStatus($this
          ->t('This page should be used for currently active domain @type.', $args));
        $this
          ->setRedirectResponse($event, 'domain_lang.negotiation_session', $domain);
        break;
      case 'language.negotiation_browser':
        $args = [
          '@type' => $this
            ->t('Browser language detection configuration'),
        ];
        $this->messenger
          ->addStatus($this
          ->t('You was redirected to current active domain @type page.', $args));
        $this->messenger
          ->addStatus($this
          ->t('This page should be used for currently active domain @type.', $args));
        $this
          ->setRedirectResponse($event, 'domain_lang.negotiation_browser', $domain);
        break;
      case 'language.negotiation_url':
        $args = [
          '@type' => $this
            ->t('URL language detection configuration'),
        ];
        $this->messenger
          ->addStatus($this
          ->t('You was redirected to current active domain @type page.', $args));
        $this->messenger
          ->addStatus($this
          ->t('This page should be used for currently active domain @type.', $args));
        $this
          ->setRedirectResponse($event, 'domain_lang.negotiation_url', $domain);
        break;
      case 'language.negotiation_selected':
        $args = [
          '@type' => $this
            ->t('Selected language configuration'),
        ];
        $this->messenger
          ->addStatus($this
          ->t('You was redirected to current active domain @type page.', $args));
        $this->messenger
          ->addStatus($this
          ->t('This page should be used for currently active domain @type.', $args));
        $this
          ->setRedirectResponse($event, 'domain_lang.negotiation_selected', $domain);
        break;
    }
  }
}