Returns the route_name matching a URL.
string $link_path: The link path to find a route name for.
string The route name.
protected function findRouteName($link_path) {
// Look up the route_name used for the given path.
$request = Request::create('/' . $link_path);
$request->attributes
->set('system_path', $link_path);
try {
// Use router.dynamic instead of router, because router will call the
// legacy router which will call hook_menu() and you will get back to
// this method.
$result = \Drupal::service('router.dynamic')
->matchRequest($request);
return isset($result['_route']) ? $result['_route'] : '';
} catch (\Exception $e) {
return '';
}
}