Advanced custom access check error calling Url::access

Created on 16 June 2023, over 1 year ago
Updated 17 June 2023, over 1 year ago

Problem/Motivation

I want to check access of route.
This route has advanced custom access checks as defined in https://www.drupal.org/docs/8/api/routing-system/access-checking-on-rout... .

Calling Following code generate error :

$url = Url::fromRoute($name, $parameters, $options);
$access = $url->access();

Error:

RuntimeException: Callable "Drupal\favorite_medias\Access\AddFavoriteMediaAccess::access" requires a value for the "$request" argument. in Drupal\Component\Utility\ArgumentsResolver->handleUnresolvedArgument() (line 143 of core/lib/Drupal/Component/Utility/ArgumentsResolver.php). 

Steps to reproduce

  1. Create an advanced custom route as defined in https://www.drupal.org/docs/8/api/routing-system/access-checking-on-rout...
  2. In the code, call Url::access as defined previously
  3. Access to the page to execute 2. code.

Proposed resolution

In \Drupal\Core\Access\AccessArgumentsResolverFactory::getArgumentsResolver(), request is empty, Request is empty, but is not passed to ArgumentsResolver class.

    $wildcard_arguments = [$route, $route_match, $account];
    if (isset($request)) {
      $wildcard_arguments[] = $request;
    }

Should be

    $wildcard_arguments = [$route, $route_match, $account];
    if (isset($request)) {
      $wildcard_arguments[] = $request;
    }
    else {
      $wildcard_arguments[] = new Request();
    }

May be this fix could also fix https://www.drupal.org/project/drupal/issues/3239775

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Routing 

Last updated 1 day ago

Created by

🇫🇷France goz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024