Skip to content

Instantly share code, notes, and snippets.

@jibran

jibran/path_to_request.php

Last active Apr 13, 2021
Embed
What would you like to do?
Setup current request to the given path in Drupal 8/9
<?php
// Setup page URL with all request parameters as current request and path.
$path = '/some-uri';
$request = Request::create($path);
$result = \Drupal::service('router.no_access_checks')->matchRequest($request);
$request->attributes->add($result);
\Drupal::requestStack()->push($request);
\Drupal::service('path.current')->setPath($path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment