You are here

public function AccessArgumentsResolverFactory::getArgumentsResolver in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Access/AccessArgumentsResolverFactory.php \Drupal\Core\Access\AccessArgumentsResolverFactory::getArgumentsResolver()

Returns the arguments resolver to use when running access checks.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match object to be checked.

\Drupal\Core\Session\AccountInterface $account: The account being checked.

\Symfony\Component\HttpFoundation\Request $request: Optional, the request object.

Return value

\Drupal\Component\Utility\ArgumentsResolverInterface The parametrized arguments resolver instance.

Overrides AccessArgumentsResolverFactoryInterface::getArgumentsResolver

File

core/lib/Drupal/Core/Access/AccessArgumentsResolverFactory.php, line 23
Contains \Drupal\Core\Access\AccessArgumentsResolverFactory.

Class

AccessArgumentsResolverFactory
Resolves the arguments to pass to an access check callable.

Namespace

Drupal\Core\Access

Code

public function getArgumentsResolver(RouteMatchInterface $route_match, AccountInterface $account, Request $request = NULL) {
  $route = $route_match
    ->getRouteObject();

  // Defaults for the parameters defined on the route object need to be added
  // to the raw arguments.
  $raw_route_arguments = $route_match
    ->getRawParameters()
    ->all() + $route
    ->getDefaults();
  $upcasted_route_arguments = $route_match
    ->getParameters()
    ->all();

  // Parameters which are not defined on the route object, but still are
  // essential for access checking are passed as wildcards to the argument
  // resolver. An access-check method with a parameter of type Route,
  // RouteMatchInterface, AccountInterface or Request will receive those
  // arguments regardless of the parameter name.
  $wildcard_arguments = [
    $route,
    $route_match,
    $account,
  ];
  if (isset($request)) {
    $wildcard_arguments[] = $request;
  }
  return new ArgumentsResolver($raw_route_arguments, $upcasted_route_arguments, $wildcard_arguments);
}