What is the replacement of drupal_match_path()
in Drupal 8?
The following function is removed from Drupal 8. How can I achieve same functionality in Drupal 8?
function drupal_match_path($path, $patterns) {
$regexps = &drupal_static(__FUNCTION__);
if (!isset($regexps[$patterns])) {
// Convert path settings to a regular expression.
// Therefore replace newlines with a logical or, /* with asterisks and the <front> with the frontpage.
$to_replace = array(
'/(\r\n?|\n)/', // newlines
'/\\\\\*/', // asterisks
'/(^|\|)\\\\<front\\\\>($|\|)/', // <front>
);
$replacements = array(
'|',
'.*',
'\1' . preg_quote(config('system.site')->get('page.front'), '/') . '\2',
);
$patterns_quoted = preg_quote($patterns, '/');
$regexps[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
}
return (bool) preg_match($regexps[$patterns], $path);
}