class ValidPathConstraintValidator
Same name in other branches
- 9 core/lib/Drupal/Core/Path/Plugin/Validation/Constraint/ValidPathConstraintValidator.php \Drupal\Core\Path\Plugin\Validation\Constraint\ValidPathConstraintValidator
- 8.9.x core/lib/Drupal/Core/Path/Plugin/Validation/Constraint/ValidPathConstraintValidator.php \Drupal\Core\Path\Plugin\Validation\Constraint\ValidPathConstraintValidator
- 10 core/lib/Drupal/Core/Path/Plugin/Validation/Constraint/ValidPathConstraintValidator.php \Drupal\Core\Path\Plugin\Validation\Constraint\ValidPathConstraintValidator
Constraint validator for validating system paths.
Hierarchy
- class \Drupal\Core\Path\Plugin\Validation\Constraint\ValidPathConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
Expanded class hierarchy of ValidPathConstraintValidator
File
-
core/
lib/ Drupal/ Core/ Path/ Plugin/ Validation/ Constraint/ ValidPathConstraintValidator.php, line 14
Namespace
Drupal\Core\Path\Plugin\Validation\ConstraintView source
class ValidPathConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The path validator.
*
* @var \Drupal\Core\Path\PathValidatorInterface
*/
protected $pathValidator;
/**
* Creates a new ValidPathConstraintValidator instance.
*
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* The path validator.
*/
public function __construct(PathValidatorInterface $path_validator) {
$this->pathValidator = $path_validator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('path.validator'));
}
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) : void {
if (!isset($value)) {
return;
}
$path = trim($value, '/');
if (!$this->pathValidator
->isValid($path)) {
$this->context
->addViolation($constraint->message, [
'%link_path' => $value,
]);
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ValidPathConstraintValidator::$pathValidator | protected | property | The path validator. | |
ValidPathConstraintValidator::create | public static | function | Overrides ContainerInjectionInterface::create | |
ValidPathConstraintValidator::validate | public | function | ||
ValidPathConstraintValidator::__construct | public | function | Creates a new ValidPathConstraintValidator instance. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.