LanguageCookieConditionPathIsValid.php in Language Cookie 8
File
src/Plugin/LanguageCookieCondition/LanguageCookieConditionPathIsValid.php
View source
<?php
namespace Drupal\language_cookie\Plugin\LanguageCookieCondition;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\language_cookie\LanguageCookieConditionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class LanguageCookieConditionPathIsValid extends LanguageCookieConditionBase {
protected $requestStack;
protected $currentPath;
protected $pathValidator;
public function __construct(RequestStack $request_stack, CurrentPathStack $current_path, PathValidatorInterface $path_validator, array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->requestStack = $request_stack;
$this->currentPath = $current_path;
$this->pathValidator = $path_validator;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('request_stack'), $container
->get('path.current'), $container
->get('path.validator'), $configuration, $plugin_id, $plugin_definition);
}
public function evaluate() {
$path = $this->currentPath
->getPath($this->requestStack
->getCurrentRequest());
if ($this->pathValidator
->isValid($path)) {
return $this
->pass();
}
return $this
->block();
}
}