function ValidPathConstraintValidator::validate

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

File

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

Class

ValidPathConstraintValidator
Constraint validator for validating system paths.

Namespace

Drupal\Core\Path\Plugin\Validation\Constraint

Code

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,
        ]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.