Skip to content

Instantly share code, notes, and snippets.

@jibran
Last active April 13, 2021 03:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jibran/e8d5f17aae6424934a77a16f2513420e to your computer and use it in GitHub Desktop.
Save jibran/e8d5f17aae6424934a77a16f2513420e to your computer and use it in GitHub Desktop.
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