You are here

public function LanguageAccessSubscriber::customLanguageAccess in Language access 8

Redirect pattern based url.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: A GetResponseEvent instance.

File

src/EventSubscriber/LanguageAccessSubscriber.php, line 67

Class

LanguageAccessSubscriber
Redirect .html pages to corresponding Node page.

Namespace

Drupal\language_access\EventSubscriber

Code

public function customLanguageAccess(GetResponseEvent $event) : void {
  $request = $this->requestStack
    ->getCurrentRequest();
  $request_url = $request->server
    ->get('REQUEST_URI');
  $language = $this->languageManager
    ->getCurrentLanguage();

  // Do not execute on drush.
  if (PHP_SAPI === 'cli') {
    return;
  }

  // Do nothing on a sub request.
  if ($event
    ->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
    return;
  }
  if (!$this
    ->pathIsWhitelisted($request_url)) {
    return;
  }

  // Check access to language.
  if ($this->currentUser
    ->hasPermission('access language ' . $language
    ->getId())) {
    return;
  }
  throw new AccessDeniedHttpException();
}