Url::createFromRequest

public static Url::createFromRequest(Request $request)

Returns the Url object matching a request.

SECURITY NOTE: The request path is not checked to be valid and accessible by the current user to allow storing and reusing Url objects by different users. The 'path.validator' service getUrlIfValid() method should be used instead of this one if validation and access check is desired. Otherwise, 'access_manager' service checkNamedRoute() method should be used on the router name and parameters stored in the Url object returned by this method.

Parameters

\Symfony\Component\HttpFoundation\Request $request: A request object.

Return value

static A Url object. Warning: the object is created even if the current user would get an access denied running the same request via the normal page flow.

Throws

\Drupal\Core\Routing\MatchingRouteNotFoundException Thrown when the request cannot be matched.

File

core/lib/Drupal/Core/Url.php, line 475

Class

Url
Defines an object that holds information about a URL.

Namespace

Drupal\Core

Code

public static function createFromRequest(Request $request) {
  // We use the router without access checks because URL objects might be
  // created and stored for different users.
  $result = \Drupal::service('router.no_access_checks')->matchRequest($request);
  $route_name = $result[RouteObjectInterface::ROUTE_NAME];
  $route_parameters = $result['_raw_variables']->all();
  return new static($route_name, $route_parameters);
}
doc_Drupal
2016-10-29 09:51:38
Comments
Leave a Comment

Please login to continue.