Checks access to a menu item by mocking a request for a path.
\Symfony\Component\Routing\Route $route: Router for the given menu item.
string $href: Menu path as returned by $item['href'] of menu_get_item().
bool TRUE if the user has access or FALSE if the user should be presented with access denied.
function menu_item_route_access(Route $route, $href) {
$request = Request::create('/' . $href);
$request->attributes
->set('system_path', $href);
// Attempt to match this path to provide a fully built request to the
// access checker.
try {
$request->attributes
->add(Drupal::service('router.dynamic')
->matchRequest($request));
return Drupal::service('access_manager')
->check($route, $request);
} catch (NotFoundHttpException $e) {
return FALSE;
}
}