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
Issue fork subpathauto-3468524
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
batigolixThis relates to #3606780: testProcessOutbound fails on Drupal 11.1+
Comment #5
batigolix[deleted]
Comment #6
batigolixComment #7
batigolixComment #8
batigolixWith some help, I created a first draft:
Approach: decorator on
path_alias.managerDrupal core's
AliasManager::getAliasByPath()only performs direct alias lookups. For/node/1/edit, with an alias/node/1→/kittens, it returns/node/1/editunchanged because no alias exists for the full path.MR !11 adds a decorator that extends
getAliasByPath()with sub-path traversal:The change already assumes that the ignore_list option is used which lands in #2964786: Ignore specific paths.
Comment #9
batigolix