Wednesday, 24 February 2016

Validate site url in Drupal 8

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.

No comments:

Post a Comment

PHP Codesniffer - Ignore warning errors

 Use below command to ignore warnings while generating report. phpcs -n /path_to_directory/ The above command will result only errors and ig...