Last active
February 28, 2022 10:22
-
-
Save morsok/5db2fb9dfb09757b9fdeb36ed5ad2540 to your computer and use it in GitHub Desktop.
Drupal 8 : Do something based on the referer if it's your website or another.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Drupal\Core\Url; | |
use Symfony\Component\HttpFoundation\Request; | |
function my_function() { | |
$previousUrl = \Drupal::request()->server->get('HTTP_REFERER'); | |
$fake_request = Request::create($previousUrl); | |
$url_object = \Drupal::service('path.validator')->getUrlIfValid($fake_request->getRequestUri()); | |
if ($url_object) { | |
$route_name = $url_object->getRouteName(); | |
// Do something with $route_name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yea this only validates the path.