Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Coming from #2681381: URL Alias is lost when paging forward
Problem/Motivation
When a URL alias is defined for a node/page and the page is accessed through the alias URL, drupalSettings.path.currentPath holds the route's original URL and not the alias one.
Steps to reproduce:
- create a normal content node:
node/1
- add an URL alias to the node in the 'URL path settings' box:
test/test
- call the URL alias link from the browser:
http://[mysite]/test/test
- watch the page source through the browser, drupalSettings.path.currentPath holds
"currentPath":"node\/1"
where you would expect"currentPath":"test\/test"
Proposed resolution
tbd
Remaining tasks
tbd
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#23 | 2687453-23.patch | 3.16 KB | mondrake |
#23 | interdiff_20-23.txt | 3.35 KB | mondrake |
#21 | 2016-03-18 11_30_03.png | 7.5 KB | mondrake |
#20 | 2687453-20.patch | 3.24 KB | mondrake |
Comments
Comment #2
mondrakeComment #3
mondrakeLet's see what this would break...
Comment #4
mondrakeComment #6
mondrakeReuploading for 8.2.x
Comment #8
mondrakeShould be better. Will need a test with an aliased URL.
Comment #9
mondrakeAdded tests in PathAliasTest. Not sure about aliases with non-ascii characters, though :(
Comment #10
mondrakeComment #11
dawehnerCan't we just use the current path service here?
Comment #12
Wim LeersIsn't this a BC break? Isn't this how it used to work in D7?
(Not sure about either, but those are my initial thoughts.)
Comment #13
mondrake#11
Well,
\Drupal::service('path.current')->getPath()
returns the URL to the canonical route and not to URL alias.Comment #14
mondrake#12
AFAICS, in D7 there is no
currentPath
variable inDrupal.settings
. OnlybasePath
andpathPrefix
.Comment #15
mondrake#12
I dont' know :( I think it's a matter of any contrib expecting the actual URL that has been called vs. the standard URL for the route.
In the Pagerer module we expect the 'actual' one, so to build pager links on the client side via
Drupal.url(drupalSettings.path.currentPath)
. That's the reason we have the parent issue.With this fix, the parent issue will (should) be fixed as well.
Alternatively #2154911-6: Lost the Home button when on Admin pages suggests introducing an additional
currentPathUrlAlias
variable todrupalSettings.path
. That could also work for Pagerer but will require a change there.Comment #16
Wim LeersLet's get @nod_'s thoughts.
Comment #17
mondrakeBTW, and do not know if related - it seems like nodes accessed via the URL alias do not get their active links (to self) appended with the 'is-active' class.
Comment #18
nod_Ideally we'd have both the alias and system path exposed in settings.
Comment #19
mondrakeOK I'll give a try
Comment #20
mondrakeHere we go.
Comment #21
mondrakeScreenshot of the drupalSettings.path content after applying the patch
Comment #22
nod_I'd name it currentAlias, it's already in drupalSettings.path, pretty clear it's not about something else. The rest of the names are redondant because they were ported as is from D7.
Comment #23
mondrakeDone
Comment #24
mondrakeThe patch for 8.2.x won't apply to 8.0.x
Comment #25
droplet CreditAttribution: droplet commentedDon't you should get it from clientside ? If it needed a helper:
Comment #26
mondrake@droplet
thanks for #25; in fact it turned out the right way to find the current request path was
currentRequestPath = location.pathname.slice(drupalSettings.path.baseUrl.length + drupalSettings.path.pathPrefix.length)
I implemented that for the parent issue in Pagerer contrib module.
Not sure we want to do anything here anymore. I'd be fine with a won't fix.
Comment #27
droplet CreditAttribution: droplet commentedCool. I think we can close it since no usages in CORE at the moment. And Core doesn't maintain any Util helpers in JS side.
Not sure if anyone want to build another http://left-pad.io/ for this little feature :)
Thanks All!