diff --git a/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php b/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php index ec6266a..4310621 100644 --- a/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php +++ b/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php @@ -19,10 +19,10 @@ class AccessArgumentsResolver implements AccessArgumentsResolverInterface { /** * {@inheritdoc} */ - public function getArguments(callable $callable, RouteMatchInterface $route_match, AccountInterface $account) { + public function getArguments(callable $callable, RouteMatchInterface $route_match, AccountInterface $account, Request $request = NULL) { $arguments = array(); foreach ($this->getReflector($callable)->getParameters() as $parameter) { - $arguments[] = $this->getArgument($parameter, $route_match, $account); + $arguments[$parameter->getName()] = $this->getArgument($parameter, $route_match, $account, $request); } return $arguments; } @@ -43,7 +43,7 @@ public function getArguments(callable $callable, RouteMatchInterface $route_matc * @throws \RuntimeException * Thrown when there is a missing parameter. */ - protected function getArgument(\ReflectionParameter $parameter, RouteMatchInterface $route_match, AccountInterface $account) { + protected function getArgument(\ReflectionParameter $parameter, RouteMatchInterface $route_match, AccountInterface $account, Request $request = NULL) { $upcasted_route_arguments = $route_match->getParameters()->all(); $raw_route_arguments = $route_match->getRawParameters()->all(); $parameter_type_hint = $parameter->getClass(); @@ -63,7 +63,7 @@ protected function getArgument(\ReflectionParameter $parameter, RouteMatchInterf // Otherwise, resolve $route, $route_match, and $account by type matching // only. This way, the callable may rename them in case the route defines // other parameters with these names. - foreach (array($route_match->getRouteObject(), $route_match, $account) as $special_argument) { + foreach (array($route_match->getRouteObject(), $route_match, $account, $request) as $special_argument) { if ($parameter_type_hint->isInstance($special_argument)) { return $special_argument; } diff --git a/core/lib/Drupal/Core/Access/AccessArgumentsResolverInterface.php b/core/lib/Drupal/Core/Access/AccessArgumentsResolverInterface.php index aee25ff..5636a89 100644 --- a/core/lib/Drupal/Core/Access/AccessArgumentsResolverInterface.php +++ b/core/lib/Drupal/Core/Access/AccessArgumentsResolverInterface.php @@ -25,6 +25,8 @@ * The parametrized route. * @param \Drupal\Core\Session\AccountInterface $account * The currently logged in account. + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * The parametrized route. * * @return array * An array of arguments to pass to the callable. @@ -32,6 +34,6 @@ * @throws \RuntimeException * When a value for an argument given is not provided. */ - public function getArguments(callable $callable, RouteMatchInterface $route_match, AccountInterface $account); + public function getArguments(callable $callable, RouteMatchInterface $route_match, AccountInterface $account, Request $request = NULL); } diff --git a/core/lib/Drupal/Core/Access/AccessManager.php b/core/lib/Drupal/Core/Access/AccessManager.php index ed4dab2..a14ac4b 100644 --- a/core/lib/Drupal/Core/Access/AccessManager.php +++ b/core/lib/Drupal/Core/Access/AccessManager.php @@ -201,10 +201,10 @@ public function check(RouteMatchInterface $route_match, AccountInterface $accoun $conjunction = $route->getOption('_access_mode') ?: static::ACCESS_MODE_ALL; if ($conjunction == static::ACCESS_MODE_ALL) { - return $this->checkAll($checks, $route_match, $account); + return $this->checkAll($checks, $route_match, $account, $request = NULL); } else { - return $this->checkAny($checks, $route_match, $account); + return $this->checkAny($checks, $route_match, $account, $request = NULL); } } @@ -213,7 +213,7 @@ public function check(RouteMatchInterface $route_match, AccountInterface $accoun * * @param array $checks * Contains the list of checks on the route definition. - * @param \Symfony\Component\Routing\RouteMatchInterface $route_match + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The parametrized route to check access to. * @param \Drupal\Core\Session\AccountInterface $account * The current user. @@ -221,7 +221,7 @@ public function check(RouteMatchInterface $route_match, AccountInterface $accoun * @return bool * Returns TRUE if the user has access to the route, else FALSE. */ - protected function checkAll(array $checks, RouteMatchInterface $route_match, AccountInterface $account) { + protected function checkAll(array $checks, RouteMatchInterface $route_match, AccountInterface $account, Request $request = NULL) { $access = FALSE; foreach ($checks as $service_id) { @@ -229,7 +229,7 @@ protected function checkAll(array $checks, RouteMatchInterface $route_match, Acc $this->loadCheck($service_id); } - $service_access = $this->performCheck($service_id, $route_match, $account); + $service_access = $this->performCheck($service_id, $route_match, $account, $request); if ($service_access === AccessInterface::ALLOW) { $access = TRUE; @@ -249,7 +249,7 @@ protected function checkAll(array $checks, RouteMatchInterface $route_match, Acc * * @param array $checks * Contains the list of checks on the route definition. - * @param \Symfony\Component\Routing\RouteMatchInterface $route_match + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The parametrized route to check access to. * @param \Drupal\Core\Session\AccountInterface $account * The current user. @@ -257,7 +257,7 @@ protected function checkAll(array $checks, RouteMatchInterface $route_match, Acc * @return bool * Returns TRUE if the user has access to the route, else FALSE. */ - protected function checkAny(array $checks, RouteMatchInterface $route_match, AccountInterface $account) { + protected function checkAny(array $checks, RouteMatchInterface $route_match, AccountInterface $account, Request $request = NULL) { // No checks == deny by default. $access = FALSE; @@ -266,7 +266,7 @@ protected function checkAny(array $checks, RouteMatchInterface $route_match, Acc $this->loadCheck($service_id); } - $service_access = $this->performCheck($service_id, $route_match, $account); + $service_access = $this->performCheck($service_id, $route_match, $account, $request); if ($service_access === AccessInterface::ALLOW) { $access = TRUE; @@ -284,7 +284,7 @@ protected function checkAny(array $checks, RouteMatchInterface $route_match, Acc * * @param string $service_id * The access check service ID to use. - * @param \Symfony\Component\Routing\RouteMatchInterface $route_match + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route to check access to. * @param \Drupal\Core\Session\AccountInterface $account * The current user. @@ -295,9 +295,14 @@ protected function checkAny(array $checks, RouteMatchInterface $route_match, Acc * @return string * A \Drupal\Core\Access\AccessInterface constant value. */ - protected function performCheck($service_id, RouteMatchInterface $route_match, AccountInterface $account) { + protected function performCheck($service_id, RouteMatchInterface $route_match, AccountInterface $account, Request $request = NULL) { $callable = array($this->checks[$service_id], $this->checkMethods[$service_id]); $arguments = $this->argumentsResolver->getArguments($callable, $route_match, $account); + + if ($request && empty($arguments['request'])) { + return AccessInterface::ALLOW; + } + $service_access = call_user_func_array($callable, $arguments); if (!in_array($service_access, array(AccessInterface::ALLOW, AccessInterface::DENY, AccessInterface::KILL), TRUE)) { diff --git a/core/lib/Drupal/Core/Access/AccessManagerInterface.php b/core/lib/Drupal/Core/Access/AccessManagerInterface.php index 8ac32d9..f08dd10 100644 --- a/core/lib/Drupal/Core/Access/AccessManagerInterface.php +++ b/core/lib/Drupal/Core/Access/AccessManagerInterface.php @@ -51,7 +51,7 @@ * @return bool * Returns TRUE if the user has access to the route, otherwise FALSE. */ - public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account); + public function checkNamedRoute($route_name, array $parameters, AccountInterface $account); /** * Execute access checks against the incomming request. diff --git a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php index 60eda70..4e5df90 100644 --- a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php +++ b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php @@ -10,7 +10,6 @@ use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Cmf\Component\Routing\ChainRouter; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\RequestContext;