When viewing an entity with an alias, the edit link sets the destination path using the system path, rather than the alias.

So after editing, the user is returned to the system path - e.g. node/1.

This is likely to be confusing and annoying for content editors.

For example, from a taxonomy term with the alias technologies/drupal, the edit link is taxonomy/term/11/edit?destination=taxonomy/term/11

Comments

malcomio created an issue. See original summary.

swentel’s picture

Hmm, I think this is the same behavior as in D7.

Another way to see it is that a redirect should try to redirect to the aliased version of it, instead of putting it in the destination.
I'm guessing that's why there are modules like redirect/global redirect.

swentel’s picture

malcomio’s picture

Component: routing system » contextual.module

Having dug into this further, the problem here is specific to contextual links - if the "Tabs" block appears, the edit link doesn't explicitly set the destination of the edit form, but just takes you to node/123/edit.

In both D7 and D8, If you go to node/123/edit and save, you are sent to the aliased path as expected.

In D8, when you're viewing the node on its own page, the edit link that is provided by contextual links includes the unaliased path in the destination query string.

malcomio’s picture

Hmm, not so sure that contextual.module is the right component any more.

contextual.js gets the destination from drupalSettings.path.currentPath, which is set to the un-aliased path in system_js_settings_alter

$current_path = \Drupal::routeMatch()->getRouteName() ? Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath() : '';

Looks like currentPath is also used in toolbar and core/misc/active-link.js

Maybe it's better for contextual.js to get the destination from the browser rather than Drupal settings?

wim leers’s picture

Title: Destination after editing entities does not use aliased paths » Contextual links destination uses internal paths, not path aliases
Priority: Minor » Normal
Status: Active » Needs review
Issue tags: +JavaScript, +Needs tests
Related issues: +#2136507: Use client-side cache tags & caching to eliminate 1 HTTP requests/page for rendering Contextual Links
StatusFileSize
new2.07 KB

Confirmed. Great catch.

Maybe it's better for contextual.js to get the destination from the browser rather than Drupal settings?

#2136507: Use client-side cache tags & caching to eliminate 1 HTTP requests/page for rendering Contextual Links introduced that behavior (to use currentPath from drupalSettings). The subtle difference is that that means that we now use:

$current_path = $route_match->getRouteName() ? Url::fromRouteMatch($route_match)->getInternalPath() : '';

whereas we used to use:

$this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::buildQuery(UrlHelper::filterQueryParameters($query->all()))]);

Therefore, I think we want to add something like currentPathProcessed. Rough patch attached.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +needs profiling

So we have code executed on a lot of page requests, right? Let's see how much additional cost this needs.
Can we maybe move this to contextual module only? I could totally imagine that people turn off contextual module on production.

wim leers’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -needs profiling
StatusFileSize
new1.3 KB

A single additional URL being generated needs profiling? Also note that this is merely reintroducing code that used to run anyway.

Also: I wonder what @nod_ thinks about using window.location.pathname. I currently can't think of a reason not to use that. That'd make all this much simpler :) Thoughts? I feel like I'm forgetting about some crucial reason to not use this?

malcomio’s picture

Digging through the git history of contextual.js it seems like it's been using drupalSettings to get the current path since #914382: Contextual links incompatible with render cache.

I don't know the history of the render cache issue, but I can't think of a reason why we can't just get the current URL via Javascript.

dawehner’s picture

I guess a reason why it was there is that people wanted to link to the path alias, even if you are on a non path alias page, which is, well, probably really helpful SEO optimization.

wim leers’s picture

#10: contextual links are only for authenticated users. So I don't see how this can be related to SEO?

dawehner’s picture

I'm just guessing.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

grahl’s picture

Status: Needs review » Needs work

I came to this issue in search of a problem with missing language path prefixes (e.g. '/fr/') since my editors were getting sent to '/node/123' instead of '/fr/node/123', which I reported here: https://www.drupal.org/node/2707879

In my opinion using aliased path is not an option for the contextual module here primarily because the aliased path can change. I verified that with patch 8 and trying to rename a node with an automatic alias which afterwards resulted in a 404. If the aliased path should be returned this would have to be done during the processing of the submission, the destination parameter has to be kept as an internal path.

droplet’s picture

#10, #11, #12,

A bit helpful for SEO. Because SEO also including sharing links. (But really a little only.) Also UX problems.

#14,
Yes, that's a case

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

reekris’s picture

I just wanted to chime in that I solved this problem for a current Drupal 8 project using the Redirect module. After activating "Normalize aliases" in the Redirect settings the module redirects me to the aliased url after editing a node. It will also solve the problem mentioned in #14 so that if the alias gets changed by the edits I make to the node, I will still be redirected to the new alias.

So maybe this should not be a responsibility of the core functionality but of third party modules, as mentioned in #2?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gngn’s picture

I do not like to use the (aliased) pathname from the browser, I think something like en/node/XYZ is much cleaner.

The solution proposed by jherencia at 2707879#10 worked for me, patch in #12

droplet’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

peter törnstrand’s picture

StatusFileSize
new1.2 KB

For 8.5.6...

peter törnstrand’s picture

StatusFileSize
new1.3 KB
caspervoogt’s picture

This is also an issue when configuring blocks from the frontend. If the block is assigned to /some-page and then you configure it from /some-page, after saving the block it redirects you to /node/123 (or whatever node ID /some-page has). And the block then does not show, unless it is assigned to both /some-page and /node/123. That's more than just annoying... it is bewildering to site editors..

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

eugene.brit’s picture

For 8.6.12

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

t-lo’s picture

Re-roll for 9.1x+

malcomio’s picture

Status: Needs work » Needs review
mitthukumawat’s picture

StatusFileSize
new24.27 KB

I have tested patch #34 manually and it reflects the changes in contextual links aliases instead using internal path of any node.
I have created a taxonomy with url alias and before patch, it was appearing taxonomy/1/edit but after patch, it is now showing url alias in destination of link.
Adding after patch screenshot for reference.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative

#14 sounds like this doesn't work with language prefixes

#18 points out that there's a contrib way to solve this - are we sure we still want to pursue this?

We need this change in the .es6 version, with the .js version generated from running yarn build

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

phoang’s picture

StatusFileSize
new1.5 KB
phoang’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB

Applies patch for core 9.5.2

smustgrave’s picture

Status: Needs review » Needs work

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This is tagged for needing tests which still need to happen.

_utsavsharma’s picture

StatusFileSize
new1.15 KB
new1.15 KB

Patch for 10.1.x as in the previous test the patch failed to apply.

praveenpb’s picture

It seems this has been fixed in 9.5.4+ and 10.0.4+ versions. Can we close this issue?

smustgrave’s picture

Status: Needs work » Closed (duplicate)