Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function isValid($path)
 {
     // External URLs and the front page are always valid.
     if ($path == '<front>' || UrlHelper::isExternal($path)) {
         return TRUE;
     }
     // Check the routing system.
     $collection = $this->routeProvider->getRoutesByPattern('/' . $path);
     if ($collection->count() == 0) {
         return FALSE;
     }
     $request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), '/' . $path);
     $request->attributes->set('_system_path', $path);
     // We indicate that a menu administrator is running the menu access check.
     $request->attributes->set('_menu_admin', TRUE);
     // Attempt to match this path to provide a fully built request to the
     // access checker.
     try {
         $request->attributes->add($this->requestMatcher->matchRequest($request));
     } catch (ParamNotConvertedException $e) {
         return FALSE;
     }
     // Consult the access manager.
     $routes = $collection->all();
     $route = reset($routes);
     return $this->accessManager->check($route, $request, $this->account);
 }
Esempio n. 2
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;
     }
 }
Esempio n. 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;
     }
 }