Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Url.php

function 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

Symfony\Component\Routing\Exception\NoConfigurationException If no routing configuration could be found.

Symfony\Component\Routing\Exception\ResourceNotFoundException If no matching resource could be found.

Symfony\Component\Routing\Exception\MethodNotAllowedException If a matching resource was found but the request method is not allowed.

2 calls to Url::createFromRequest()
OEmbedIframeController::render in core/modules/media/src/Controller/OEmbedIframeController.php
Renders an oEmbed resource.
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 492

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);
}
RSS feed
Powered by Drupal