class ValidPathConstraintValidator in Drupal 8
Same name and namespace in other branches
- 9 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 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) {
if (!isset($value)) {
return;
}
$path = trim($value, '/');
if (!$this->pathValidator
->isValid($path)) {
$this->context
->addViolation($constraint->message, [
'%link_path' => $value,
]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ValidPathConstraintValidator:: |
protected | property | The path validator. | |
ValidPathConstraintValidator:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ValidPathConstraintValidator:: |
public | function | Checks if the passed value is valid. | |
ValidPathConstraintValidator:: |
public | function | Creates a new ValidPathConstraintValidator instance. |