class ValidPathConstraintValidator

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Path/Plugin/Validation/Constraint/ValidPathConstraintValidator.php \Drupal\Core\Path\Plugin\Validation\Constraint\ValidPathConstraintValidator
  2. 10 core/lib/Drupal/Core/Path/Plugin/Validation/Constraint/ValidPathConstraintValidator.php \Drupal\Core\Path\Plugin\Validation\Constraint\ValidPathConstraintValidator
  3. 11.x core/lib/Drupal/Core/Path/Plugin/Validation/Constraint/ValidPathConstraintValidator.php \Drupal\Core\Path\Plugin\Validation\Constraint\ValidPathConstraintValidator

Constraint validator for validating system paths.

Hierarchy

Expanded class hierarchy of ValidPathConstraintValidator

File

core/lib/Drupal/Core/Path/Plugin/Validation/Constraint/ValidPathConstraintValidator.php, line 14

Namespace

Drupal\Core\Path\Plugin\Validation\Constraint
View 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

Title Sort descending Modifiers Object type Summary Overriden Title
ValidPathConstraintValidator::$pathValidator protected property The path validator.
ValidPathConstraintValidator::create public static function Instantiates a new instance of this class. 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.