function menu_item_route_access

Checks access to a menu item by mocking a request for a path.

Parameters

\Symfony\Component\Routing\Route $route: Router for the given menu item.

string $href: Menu path as returned by $item['href'] of menu_get_item().

Return value

bool TRUE if the user has access or FALSE if the user should be presented with access denied.

Related topics

2 calls to menu_item_route_access()
_menu_link_translate in drupal/core/includes/menu.inc
Provides menu link access control, translation, and argument handling.
_menu_translate in drupal/core/includes/menu.inc
Handles dynamic path translation and menu access control.

File

drupal/core/includes/menu.inc, line 961
API for the Drupal menu system.

Code

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;
  }
}