- Issue created by @erwangel
With standard pathauto we can get the aliased path with getAliasByPath. This doesn't work if we have a subpath.
Take a standard node: node/12345 aliased as "mynodealias"
Alter its path to add a subpath "mysubpath" with alterRoutes (inside "class RouteSubscriber extends RouteSubscriberBase") or any other way
Visit "node/12345" which will redirect to "mynodealias"
Test in node_view_alter:
$request = \Drupal::request();
$uri = $request->getRequestUri();
dpm($uri, 'uri'); will print "/mynodealias"
$current_path = \Drupal::service('path.current')->getPath();
dpm($current_path, 'current path'); will print "/node/12345"
$alias= \Drupal::service('path_alias.manager')->getAliasByPath($current_path);
dpm($alias, 'alias'); will print "/mynodealias" -> AS EXPECTED
Visit "node/12345/mysubpath" which will redirect to "mynodealias/mysubpath"
Test:
$request = \Drupal::request();
$uri = $request->getRequestUri();
dpm($uri, 'uri'); will print "/mynodealias/mysubpath"
$current_path = \Drupal::service('path.current')->getPath();
dpm($current_path, 'current path'); will print "/node/12345"
$alias= \Drupal::service('path_alias.manager')->getAliasByPath($current_path);
dpm($alias, 'alias'); will print "/node/12345/mysubpath" -> EXPECTED "/mynodealias/mysubpath"
You can verify the same with user's contact form
uri => "/users/name/contact"
current path => "/user/1234/contact"
alias (with getAliasByPath) => "/user/1234/contact" INSTEAD OF "/users/name/contact"
Active
1.3
Code