Make Sub-pathauto compatible with getAliasByPath

Created on 16 August 2024, 3 months ago

Problem/Motivation

With standard pathauto we can get the aliased path with getAliasByPath. This doesn't work if we have a subpath.

Steps to reproduce

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"

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.3

Component

Code

Created by

🇫🇷France erwangel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024