If we have path, we can validate that path using below code. The path may be a direct node or url alias of the node.
Example:
$input_path = "node/1";
$pathValidator = \Drupal::pathValidator()->getUrlIfValid($input_path);
if($pathValidator){
print "Valid Path";
}else{
print "Invalid Path";
}
Hope this help.
Example:
$input_path = "node/1";
$pathValidator = \Drupal::pathValidator()->getUrlIfValid($input_path);
if($pathValidator){
print "Valid Path";
}else{
print "Invalid Path";
}
Hope this help.
No comments:
Post a Comment