LanguageCookieConditionLanguageAccess.php in Language Cookie 8
File
src/Plugin/LanguageCookieCondition/LanguageCookieConditionLanguageAccess.php
View source
<?php
namespace Drupal\language_cookie\Plugin\LanguageCookieCondition;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\language_cookie\LanguageCookieConditionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LanguageCookieConditionLanguageAccess extends LanguageCookieConditionBase {
protected $currentUser;
protected $moduleHandler;
public function __construct(AccountInterface $current_user, ModuleHandlerInterface $module_handler, array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->moduleHandler = $module_handler;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('current_user'), $container
->get('module_handler'), $configuration, $plugin_id, $plugin_definition);
}
public function evaluate() {
$current_language = $this
->getCurrentLanguage();
if ($this->moduleHandler
->moduleExists('language_access') && (!$current_language instanceof LanguageInterface || !$this->currentUser
->hasPermission('access language ' . $current_language
->getId()))) {
return $this
->block();
}
return $this
->pass();
}
}