You are here

public static function Url::createFromRequest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Url.php \Drupal\Core\Url::createFromRequest()

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.

5 calls to Url::createFromRequest()
UnroutedUrlTest::testCreateFromRequest in core/tests/Drupal/Tests/Core/UnroutedUrlTest.php
Tests the createFromRequest method.
UrlTest::testCreateFromRequest in core/tests/Drupal/Tests/Core/UrlTest.php
Tests the createFromRequest method.
UrlTest::testUrlFromRequest in core/tests/Drupal/Tests/Core/UrlTest.php
Tests creating a Url from a request.
UrlTest::testUrlFromRequestInvalid in core/tests/Drupal/Tests/Core/UrlTest.php
Tests that an invalid request will thrown an exception.
ViewEditForm::submitDelayDestination in core/modules/views_ui/src/ViewEditForm.php
Submit handler for form buttons that do not complete a form workflow.

File

core/lib/Drupal/Core/Url.php, line 496
Contains \Drupal\Core\Url.

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);
}