Drupal 8/9 - current_uri , current_path, Alias mit/ohne Language Code

Submitted by Gast (nicht überprüft) on Mo, 02/08/2021 - 14:46

Current Url



$current_url = Url::fromRoute('<current>');
$path = $current_url->toString();



 

Current Url : Internal Path / Route Name




$current_url->toString();    # /en/user/login
$current_url->getInternalPath();    # user/login
$path = $current_url->getRouteName();   # <current>


 

System Path



$path = \Drupal::request()->attributes->get('_system_path');

 

Current Uri




$current_uri_with_query_string = \Drupal::request()->getRequestUri();



 

Current Path : Alias by Path


$current_path = \Drupal::service('path.current')->getPath(); 
$alias_by_path = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);

 

 

 

Neuen Kommentar schreiben

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.