Some (like) would find it strange that admin paths are also processed with aliases. For this use case I added validation and setting to enable/disable this validation.

CommentFileSizeAuthor
#62 2830425.patch10.82 KBkorn3000
#60 3138032.patch15.21 KBkorn3000
#58 Screenshot 2025-06-11 at 12.02.58 PM.png57.73 KBanup.singh
#57 Screenshot 2025-06-11 at 12.03.04 PM.png24.25 KBanup.singh
#50 2830425-50.patch11.95 KBneclimdul
#48 2830425-45.patch11.27 KBkristyb23
#44 2830425-44.patch10.93 KBneclimdul
#44 2830425-44.interdiff.txt431 bytesneclimdul
#43 2830425-43.patch45.35 KBneclimdul
#43 2830425-43.interdiff.txt3.13 KBneclimdul
#38 subpathauto-add_option_to_ignore_admin_paths-2830425-38.patch10.54 KBfskreuz
#36 Screenshot Before.png115.91 KBrinku jacob 13
#36 Screenshot After.png155.43 KBrinku jacob 13
#34 2830425-34.interdiff.txt6.47 KBneclimdul
#34 2830425-34.patch11.01 KBneclimdul
#31 interdiff_28-31.txt3.63 KBvidorado
#31 2830425-31.patch9.25 KBvidorado
#29 Screen Shot 2021-08-31 at 6.07.44 PM.png40.52 KBbanoodle
#28 2830425-28.patch8.07 KBsuresh prabhu parkala
#27 2830425-27.patch8.55 KBvidorado
#26 2830425-26.patch8.59 KBvidorado
#25 2830425-25.patch7.05 KBjamiehollern
#23 interdiff_21-22.txt13.6 KBjamiehollern
#23 2830425-22.patch14.8 KBjamiehollern
#21 2830425-21.patch6.28 KBabu-zakham
#20 2830425-20.patch5.18 KBfirass.ziedan
#19 2830425-18.patch5.74 KBfirass.ziedan
#17 subpathauto-2830425-17.patch4.95 KBmikhailkrainiuk
#16 subpathauto-2830425-16.patch4.95 KBmikhailkrainiuk
#15 subpathauto-2830425-15.patch4.31 KBmikhailkrainiuk
#12 2830425-skip_admin_routes-11.patch3.83 KBjuampynr
#9 2830425-skip_admin_routes-9.patch3.71 KBslv_
#4 subpathauto-admin_route_validation-2830425-4.patch4.05 KBjefuri
subpathauto-admin_route_validation.patch5.26 KBjefuri
Command icon 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

jbertoen created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, subpathauto-admin_route_validation.patch, failed testing.

lauriii’s picture

Issue tags: +Needs tests

Thanks for the patch and the issue! I'm +1 for adding this feature.

When creating your next patch, could you take a look how to create patches for Drupal projects here: https://www.drupal.org/node/707484 .

  1. +++ modules/contrib/subpathauto/subpathauto.install	(revision )
    @@ -0,0 +1,10 @@
    +  $config->set('admin_route_validation', true);
    

    We will most likely have to set this for the existing installation to FALSE since we don't want to change the behaviour on them.

  2. +++ modules/contrib/subpathauto/src/PathProcessor.php	(revision )
    @@ -181,6 +182,31 @@
    +    if($this->configFactory->get('subpathauto.settings')->get('admin_route_validation')) {
    

    Missing space after if

  3. +++ modules/contrib/subpathauto/config/install/subpathauto.settings.yml	(revision )
    @@ -1,1 +1,2 @@
    \ No newline at end of file
    

    Missing newline from the end of the file

  4. +++ modules/contrib/subpathauto/src/Form/SettingsForm.php	(revision )
    @@ -25,6 +25,13 @@
    +      '#title' => $this->t('If validation of admin routes is wanted'),
    

    I think this would be clearer if this would be "Skip administration paths from sub-path processing.".

Beside this, we should add test coverage for this feature. We probably also should consider extending this for the inbound processor (especially if that could be done easily).

jefuri’s picture

Status: Needs work » Needs review
StatusFileSize
new4.05 KB

Fixed, sorry about that. Was kind of a noob in patches.

Status: Needs review » Needs work

The last submitted patch, 4: subpathauto-admin_route_validation-2830425-4.patch, failed testing.

jefuri’s picture

Status: Needs work » Needs review
abu-zakham’s picture

Status: Needs review » Needs work

Hello, patch #4 breaking /admin/content when "Content Translation" module installed.

RumyanaRuseva’s picture

slv_’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

Hi there,

Attaching a modified version of the patch from @jefuri. It does the same, but changes a bit the wording of things to be closer to the behavior. It can also be applied to current latest version of the module, which has moved since the last time the patch was re-rolled.

One note, from the module description:

In combination with the Pathauto module it is possible to get rid of all remaining exposed internal non-administrative URLs.

I'd argue this is not a feature request, but actually a bug (even if minor), since according to the module description, the default behavior would be to *not* apply it to admin routes.

NOTE: I haven't been able to test with content translation enabled.

Status: Needs review » Needs work

The last submitted patch, 9: 2830425-skip_admin_routes-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

juampynr’s picture

+++ b/src/PathProcessor.php
@@ -177,6 +182,32 @@ class PathProcessor implements InboundPathProcessorInterface, OutboundPathProces
+        ->matchRequest($request);

Doesn't this throw an exception when a route does not exist?

juampynr’s picture

Status: Needs work » Needs review
StatusFileSize
new3.83 KB

Here is a patch that fixes it.

Status: Needs review » Needs work

The last submitted patch, 12: 2830425-skip_admin_routes-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

slv_’s picture

ah, great catch! I re-rolled the existing patch and didn't notice that could happen.

mikhailkrainiuk’s picture

StatusFileSize
new4.31 KB

Hello!

I added a small optimization to the previous patch to fix autotest warning.

mikhailkrainiuk’s picture

StatusFileSize
new4.95 KB

And second fix to the similar warning in autotests.

mikhailkrainiuk’s picture

StatusFileSize
new4.95 KB

Sorry, on #15 comment I made a mistake. Real Drupal config gives "0" instead "FALSE" and comparsion with "===" does not work.
Fixed.

After changes autotests generate a notice about method, but I don't know how to fix it.
> Method was expected to be called 2 times, actually called 1 times.

firass.ziedan’s picture

Version: 8.x-1.0-beta1 » 8.x-1.x-dev
firass.ziedan’s picture

StatusFileSize
new5.74 KB
firass.ziedan’s picture

StatusFileSize
new5.18 KB
abu-zakham’s picture

Status: Needs work » Needs review
StatusFileSize
new6.28 KB

I have added another config "process_layout_builder_route" for layout builder route (not admin route), I have issue when layout builder enabled on taxonomy term page on multilaingual site

Status: Needs review » Needs work

The last submitted patch, 21: 2830425-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jamiehollern’s picture

Status: Needs work » Needs review
StatusFileSize
new14.8 KB
new13.6 KB

Fixed the tests - one was a code issue and one was a test code issue.

Status: Needs review » Needs work

The last submitted patch, 23: 2830425-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jamiehollern’s picture

StatusFileSize
new7.05 KB

Last patch was garbage.

vidorado’s picture

StatusFileSize
new8.59 KB

Fixed tests and a default configuration issue with max depth that was being set to 1 instead of 0 (no max depth)

vidorado’s picture

StatusFileSize
new8.55 KB

Sorry, there was a mistake in the last patch.

I've had to remove a (I think) false passing test. It was passing because the function getMaxDepth was returning NULL instead of 0.

I don't understand very well that test purpose, I think it should be revised.

Now, with this patch, everything seems to work well for me.

Patch is against subpathauto version 1.1, it would need a reroll for dev!!

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new8.07 KB

Re-roll against the latest dev.

banoodle’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new40.52 KB

Patch #28 worked well on current dev branch (1.x-dev). Looks good - thank you!!!!

Screenshot of admin config form for subpathauto

mistergroove’s picture

Has anyone rerolled this patch for 8.x-1.2 yet? Would love this functionality to make it into the release.

vidorado’s picture

StatusFileSize
new9.25 KB
new3.63 KB

@mistergroove The patch in #28 applied cleanly over v1.2

However, in large forms (like a node edit form with a lot of fields), I have detected a low performance in checking for admin or layout builder routes, so I've added a caching layer.

mistergroove’s picture

Sorry I'm only just getting back to you. Drupal 9 updates seemed to have consumed me for an eternity. This is great @vidorado. I'll test it this week and get back to you.

neclimdul’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/PathProcessor.php
@@ -218,4 +293,60 @@ protected function getMaxDepth() {
+    $request = Request::create($path);
...
+    $request = Request::create($path);

This has a quirky bug that can be triggered in some edge cases. Don't think its affecting the functionality of the patch in real use cases but it does have the ability to cause deprecation warnings in PHP 8.1 and be broken for really weird paths.

The problem is that $path here is the raw unescaped path from processOutbound. This is unclear from the documentation but its the case and it makes sense that it wouldn't be encoded until needed after processing. The reason this is a problem for this code gets pretty technical but has to do with the fact Request::create wants a URI and passes it parse_url. Technically the path isn't a full uri but a valid one is good enough to get parsed and work however a _raw_ path as passed to process can include invalid path characters which have not yet been encoded.

To understand, here's a real example:

Take this path created by memcache_admin module:
/admin/reports/memcache/default/cache2%3A11211

If you had code that did (new Url('<current>')->toString() on that page it would trigger the out bound processing and it gets sent the raw path /admin/reports/memcache/default/cache:11211. Now that gets sent into the ::create method and through parse_url. parse_url is like "it looks like there's a port but everything before it is scuffed so this isn't a valid url" returns false. This actually kinda sends Symfony down undefined code path that triggers this deprecation https://github.com/symfony/symfony/issues/47084 and just generally doesn't work. The current behavior actually then processes the / path and gets route which gets the wrong route and admin/lb values.

As noted, I don't expect this generally affects any real world uses but it does cause a deprecation warning and in some future PHP version an error.

The maybe obvious solution of using rawurlencode doesn't work because it encodes '/' so this probably has to manually escape some things which feels icky but is probably the right solution.

Bonus review:

  1. This pattern:
    $request = Request::create($path);
    $match = $router->matchRequest($request);
    

    is the same as the much easier to read

    $match = $router->match($path);
    
  2. The router services should be injected into the constructor.
neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new11.01 KB
new6.47 KB

Here's an updated patch. It addresses my review but also makes this patch D10 compatible.

Also this restores the test that was removed in #28

Probably still needs real tests though.

rinku jacob 13’s picture

Hi @neclimdul ,Reviewed the patch on drupal version 9.5.3-dev. I think Sub-pathauto (Sub-path URL Aliases) Version: 8.x-1.x-dev Works with druapl versions 8 and 9. it is not compatible with D10. So i have tested the patch with drupal9. Patch works perfectly for me. Need RTBC+1.
Before applying the patch
Before
After applying the patch
After

rinku jacob 13’s picture

StatusFileSize
new155.43 KB
new115.91 KB
nickdickinsonwilde’s picture

Status: Needs review » Needs work

Needs re-roll

fskreuz’s picture

StatusFileSize
new10.54 KB

Reroll

fskreuz’s picture

Status: Needs work » Needs review
nickdickinsonwilde’s picture

Status: Needs review » Needs work

Testing concern:
- The default value of `process_admin_routes` is TRUE. However, in the `/tests/src/Kernel/SubPathautoKernelTest.php b/tests/src/Kernel/SubPathautoKernelTest.php` we have `\Drupal::configFactory()->getEditable('subpathauto.settings')->set('process_admin_routes', TRUE)->save();` Instead of replicating the default setting, in the test it should start with default settings and then toggle the setting and confirm it is working as expected.

nickdickinsonwilde’s picture

Assigned: jefuri » Unassigned
mistergroove’s picture

Great work anyone involved in this patch so far. Does anyone else consider this essential functionality for subpathauto? Would be great to get this into the official release.

neclimdul’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.13 KB
new45.35 KB

Improved testing. Does what Nick suggested plus a bit more because it doesn't look like there was any _actual_ testing of the new feature provided here.

neclimdul’s picture

StatusFileSize
new431 bytes
new10.93 KB

woops... diff'd the wrong commit. This should be correct.

Also noticed there was a dead property on the path processor. @see interdiff.

mistergroove’s picture

Nice one @neclimdul. Will test this today.

lobsterr’s picture

Maybe we should use a generic solution #2964786: Ignore specific paths

Like this we can ignore not only admin, but any path we want. It would be more flexible

kristyb23’s picture

StatusFileSize
new11.27 KB

Re-rolled patch for 8.x-1.4

nickdickinsonwilde’s picture

Status: Needs review » Needs work

MR shouldn't be introducing any code standards issues.
see https://git.drupalcode.org/issue/subpathauto-2830425/-/pipelines/316044

neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new11.95 KB

Fixed

damienmckenna made their first commit to this issue’s fork.

damienmckenna’s picture

While testing the latest MR it gave an error that dynamic properties was deprecated, so adding the $adminCache property resolves the error.

I would suggest creating a follow-on issue to rework some of the logic to properly use DI for \Drupal::cache(), and some of the other things that are loaded via services.

damienmckenna’s picture

Status: Needs review » Reviewed & tested by the community

Marking the existing work as RTBC as it works really well.

batigolix’s picture

Status: Reviewed & tested by the community » Needs work

Can the maintainer give his opinion on this generic solution for ignoring paths?:

#2964786: Ignore specific paths

I think that approach will clash with the one proposed in this issue above.

Also the UI is not very clear:

+      '#title' => $this->t('Apply sub-paths aliases to admin routes.'),

For the user it is not clear what "admin routes" mean. Does this also apply to taxonomy and user edit paths, for example?

I would avoid the word "route" because it is quite technical and because elsewhere in the UI it says "paths".

My proposal would be: "Provide sub-path aliases for admin paths"

+      '#description' => $this->t('This will enable routes like node/[id]/edit to also be altered.'),

This is a bit hard to understand.

My proposal would be "Creates aliases for admin paths like node/[id]/edit and user/[id]/edit"

+      '#title' => $this->t('Apply sub-paths aliases to layout builder route.'),
+      '#description' => $this->t('This will enable routes like node/[id]/layout to also be altered.'),

Same issues.

My proposal would be:
"Provide sub-path aliases for layout builder paths"
"Creates aliases for layout builder paths like node/[id]/layout"

batigolix’s picture

Issue tags: +finalist-sprint

anup.singh made their first commit to this issue’s fork.

anup.singh’s picture

StatusFileSize
new24.25 KB

Added a fix to handle empty path, to replicate this issue you need to create a URL alias with just "/", screenshot attached.

anup.singh’s picture

StatusFileSize
new57.73 KB
batigolix’s picture

Status: Needs work » Postponed

I propose to postpone this, and go for the more generic solution of #2964786: Ignore specific paths

korn3000’s picture

korn3000’s picture

korn3000’s picture