/**
  * {@inheritdoc}
  */
 public function enhance(array $defaults, Request $request)
 {
     // Just run the parameter conversion once per request.
     if (!isset($defaults['_raw_variables'])) {
         $defaults['_raw_variables'] = $this->copyRawVariables($defaults);
         $defaults = $this->paramConverterManager->convert($defaults);
     }
     return $defaults;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account = NULL, $return_as_object = FALSE)
 {
     try {
         $route = $this->routeProvider->getRouteByName($route_name, $parameters);
         // ParamConverterManager relies on the route name and object being
         // available from the parameters array.
         $parameters[RouteObjectInterface::ROUTE_NAME] = $route_name;
         $parameters[RouteObjectInterface::ROUTE_OBJECT] = $route;
         $upcasted_parameters = $this->paramConverterManager->convert($parameters + $route->getDefaults());
         $route_match = new RouteMatch($route_name, $route, $upcasted_parameters, $parameters);
         return $this->check($route_match, $account, NULL, $return_as_object);
     } catch (RouteNotFoundException $e) {
         // Cacheable until extensions change.
         $result = AccessResult::forbidden()->addCacheTags(['config:core.extension']);
         return $return_as_object ? $result : $result->isAllowed();
     } catch (ParamNotConvertedException $e) {
         // Uncacheable because conversion of the parameter may not have been
         // possible due to dynamic circumstances.
         $result = AccessResult::forbidden()->setCacheMaxAge(0);
         return $return_as_object ? $result : $result->isAllowed();
     }
 }
Beispiel #3
0
 /**
  * Checks a named route with parameters against applicable access check services.
  *
  * Determines whether the route is accessible or not.
  *
  * @param string $route_name
  *   The route to check access to.
  * @param array $parameters
  *   Optional array of values to substitute into the route path patern.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The current user.
  * @param \Symfony\Component\HttpFoundation\Request $route_request
  *   Optional incoming request object. If not provided, one will be built
  *   using the route information and the current request from the container.
  *
  * @return bool
  *   Returns TRUE if the user has access to the route, otherwise FALSE.
  */
 public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account, Request $route_request = NULL)
 {
     try {
         $route = $this->routeProvider->getRouteByName($route_name, $parameters);
         if (empty($route_request)) {
             // Create a request and copy the account from the current request.
             $defaults = $parameters + $route->getDefaults();
             $route_request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), $this->urlGenerator->generate($route_name, $defaults));
             $defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
             $route_request->attributes->add($this->paramConverterManager->convert($defaults, $route_request));
         }
         return $this->check($route, $route_request, $account);
     } catch (RouteNotFoundException $e) {
         return FALSE;
     } catch (ParamNotConvertedException $e) {
         return FALSE;
     }
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account, Request $route_request = NULL)
 {
     try {
         $route = $this->routeProvider->getRouteByName($route_name, $parameters);
         if (empty($route_request)) {
             // Create a cloned request with fresh attributes.
             $route_request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), $this->urlGenerator->generate($route_name, $parameters));
             $route_request->attributes->replace(array());
             // Populate $route_request->attributes with both raw and converted
             // parameters.
             $parameters += $route->getDefaults();
             $route_request->attributes->set('_raw_variables', new ParameterBag($parameters));
             $parameters[RouteObjectInterface::ROUTE_OBJECT] = $route;
             $route_request->attributes->add($this->paramConverterManager->convert($parameters, $route_request));
         }
         return $this->check($route, $route_request, $account);
     } catch (RouteNotFoundException $e) {
         return FALSE;
     } catch (ParamNotConvertedException $e) {
         return FALSE;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function enhance(array $defaults, Request $request)
 {
     $defaults['_raw_variables'] = $this->copyRawVariables($defaults);
     return $this->paramConverterManager->convert($defaults);
 }