public function HiddenLanguageSubscriber::onKernelRequestCheckLanguageAccess in Hidden Language 8
Same name and namespace in other branches
- 2.x src/EventSubscriber/HiddenLanguageSubscriber.php \Drupal\hidden_language\EventSubscriber\HiddenLanguageSubscriber::onKernelRequestCheckLanguageAccess()
Disallow access to hidden language.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event:
File
- src/
EventSubscriber/ HiddenLanguageSubscriber.php, line 38
Class
Namespace
Drupal\hidden_language\EventSubscriberCode
public function onKernelRequestCheckLanguageAccess(GetResponseEvent $event) {
if ($event
->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
$route_name = RouteMatch::createFromRequest($event
->getRequest())
->getRouteName();
// Don't check access if user is trying to log in, register or reset password.
if ($this->account
->isAuthenticated() || !in_array($route_name, array(
'user.login',
'user.pass',
'user.register',
))) {
$currentLanguage = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
// Check if user has access to hidden languages.
if (!$this->account
->hasPermission('access all hidden languages') && !$this->account
->hasPermission("access hidden language {$currentLanguage}")) {
/** @var ConfigurableLanguage $language */
$language = ConfigurableLanguage::load($currentLanguage);
if ($language
->getThirdPartySetting('hidden_language', 'hidden', FALSE)) {
throw new AccessDeniedHttpException();
}
}
}
}
}