/**
  * {@inheritdoc}
  */
 public function buildUrl($path, $clean_urls = NULL)
 {
     $uri = $this->buildUri($path);
     // The token query is added even if the
     // 'image.settings:allow_insecure_derivatives' configuration is TRUE, so
     // that the emitted links remain valid if it is changed back to the default
     // FALSE. However, sites which need to prevent the token query from being
     // emitted at all can additionally set the
     // 'image.settings:suppress_itok_output' configuration to TRUE to achieve
     // that (if both are set, the security token will neither be emitted in the
     // image derivative URL nor checked for in
     // \Drupal\image\ImageStyleInterface::deliver()).
     $token_query = array();
     if (!\Drupal::config('image.settings')->get('suppress_itok_output')) {
         // The passed $path variable can be either a relative path or a full URI.
         $original_uri = file_uri_scheme($path) ? file_stream_wrapper_uri_normalize($path) : file_build_uri($path);
         $token_query = array(IMAGE_DERIVATIVE_TOKEN => $this->getPathToken($original_uri));
     }
     if ($clean_urls === NULL) {
         // Assume clean URLs unless the request tells us otherwise.
         $clean_urls = TRUE;
         try {
             $request = \Drupal::request();
             $clean_urls = RequestHelper::isCleanUrl($request);
         } catch (ServiceNotFoundException $e) {
         }
     }
     // If not using clean URLs, the image derivative callback is only available
     // with the script path. If the file does not exist, use Url::fromUri() to
     // ensure that it is included. Once the file exists it's fine to fall back
     // to the actual file path, this avoids bootstrapping PHP once the files are
     // built.
     if ($clean_urls === FALSE && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
         $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
         return Url::fromUri('base:' . $directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query))->toString();
     }
     $file_url = file_create_url($uri);
     // Append the query string with the token, if necessary.
     if ($token_query) {
         $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($token_query);
     }
     return $file_url;
 }
Exemple #2
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);
 }
 /**
  * {@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;
     }
 }
Exemple #4
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;
     }
 }