While not mentioned in the API documentation, drupal_lookup_path will return the most recently created alias for a given path (based on having the highest pid).

Sister function path_load, will also return a single alias, but there is no explicit preference for one alias over another, so it is likely that it will return the oldest alias.

We should add an orderBy to the latter function, to make the consistent.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ianthomas_uk’s picture

Status: Active » Needs review
FileSize
362 bytes
Jody Lynn’s picture

This is a duplicate of #1160764: URL alias load is inconsistent if there are more then one alias but I think you've found the problem and the solution best.

I'm running a live site in which the inability to change aliases and have them take effect consistently is driving editors crazy. I will try this patch and report back.

Jody Lynn’s picture

Steps to reproduce the bug before the patch:

Create two aliases for a node, first alias foo and then alias bar.
View the node. It should show the newer alias, alias bar, as the URL.
Edit the node. It shows the older alias, alias foo in the edit form.
Change the alias when you edit the node. The alias for foo's pid is now changed in the database, but bar still shows when you view the node.

So, basically you can't edit your aliases without understanding the whole system and using the url alias administration page to delete the old one.

SebCorbin’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This is a big problem when using globalredirect module for example, because the user is never presented the latest url alias and won't understand why.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1: drupal-1934086-path_load_order-1.patch, failed testing.

SebCorbin’s picture

Status: Needs work » Needs review
FileSize
323 bytes

Test fail was due to Javascript. Added a range as per comment in the other issue too

Dave Reid’s picture

Status: Needs review » Closed (duplicate)
Parent issue: » #1160764: URL alias load is inconsistent if there are more then one alias

Yes, this is a duplicate, we should have only one issue open so I copied the patch from here against D7 over to that issue.