The problem:

When using [node:menu-link:title] pattern, saving a node generate paths for the old menu link title instead of the new one being saved.

Steps to reproduce this

Step 1:

  • create a node with menu link title: 'AAA'
  • set path for this node: '/aaa'
  • set pathauto pattern for a node type: '[node:menu-link:title]'
  • set pathauto action: 'Create a new alias. Delete the old alias.'

Step 2:

  • edit the node
  • change menu link title 'AAA' -> 'BBB'
  • check 'use auto path'
  • save node

Result 2:

  • the menu-title is now 'BBB' as expected
  • but the path is still '/aaa'
  • 'use auto path' checkbox is unchecked (because path doesn't match pattern)

Step 3:

  • edit the node again
  • change menu link title 'BBB' -> 'CCC'
  • re-check 'use auto path'
  • save node again

Result 3:

  • the menu link title is now 'CCC' as expected
  • but the path is now '/bbb'
  • and 'use auto path' checkbox is unchecked (same reason)

Conclusion

When saving a node, pathauto generates a path based on the menu link title before saving, then the menu link title is updated according to the edit. So I think the problem is the order of execution

Note

if pathauto pattern is set to use the node's title ([node:title] token) rather then menu link title, everything works fine.

Comments

Category:bug» support
Status:Active» Postponed (maintainer needs more info)

I'm unable to duplicate this with just core + Token + Pathauto. Changing the menu link title and then saving the node does in fact properly update the URL alias with the changed menu link title right away.

FYI: menu_node_update() runs before pathauto_node_update().

Very Odd.

I have site with only Core 7.9 + Token 1.0-beta7 + Pathauto 1.0 enabled, cleared cache. And it is exhibiting the described behaviour.

I'll look deeper into this and come back.

Status:Postponed (maintainer needs more info)» Active

I have just tested this issue again following the steps above, using a new standard installation of Drupal 7.10, Token 7.x-1.0-beta7, and Pathauto 7.x-1.0.
All modules and configurations are left as default except pathauto pattern for nodes as described above.
And the result is exactly the same.

So far, I have tested this on 2 live sites, a D7.9 devel site with all modules disabled, and a fresh installation of D7.10 with the sole purpose of testing this. All these sites are showing this behaviour. I am convinced that it's not just me so I am changing status back to active.

I still have no idea how menu_node_update() could run before pathauto_node_update(). Both modules *should* have a weight of 0 which means they should get run in alphabetical order and m comes before p. Can you check your {system} table to confirm that the weight column for both modules is zero?

Status:Active» Postponed (maintainer needs more info)

On {system} table, menu has weight 0 and pathauto has weight 1. Which means menu update should runs before pathauto update, right?

I enabled verbose setting for pathauto and edited node menu link title again. message output shows

  • Created new alias ccc for node/2, replacing bbb.
  • Basic Page Node 2 has been updated.

If drupal_set_message() output order is the same as execution order, this shows pathauto update preceeds menu update, despite menu module has a lower weight.

Same issue here. My pathauto pattern uses the menu item and alias is not updated when the menu details are changed.

I am experiencing this problem as well. It definitely looks like the pathauto update function runs before the menu function. The alias doesn't change on the initial save with menu update, but if I edit the page again and select "Generate automatic URL alias" it will generate correct. I have tested this with Core 7.12, Token 1.0 and Pathauto 1.0.

I was finally able to track down the cause of this bug on our site. We are new doing a ton of custom functionality which really changes how our paths work, however I think the bug still comes back to the same thing.

When the token module looks up the menu link item for a certain token, it caches that result. There is a pathauto_create_alias() call in pathauto_field_attach_form() that will fire this menu lookup early in the node save execution and prior to the menu item update. Thus this result is cached with the old menu item and not the new one. When the expected pathauto_create_alias() is fired in the pathauto_node_update() function, it pulls the cached results with the old menu item.

To resolve the problem we were able to manually clear the cache for that function in a hook_node_update(), in our case right before we create the pathauto alias.

drupal_static_reset('token_menu_link_load');

I can confirm this is happening in the 7.1.1 version too.
I am working on a similar issue with the [node:menu-link:parent:url:path] token - same symptoms, moving sub page from page 1 to page 2 drops the alias and won't apply until I recheck the "generate automatic..."

Adding the "drupal_static_reset('token_menu_link_load');" line to a simple module in hook_node_update() also fixes this issue

Confirmed that this is happening for me, too. Completing two node saves, with a checked auto alias, always gives the correct result, just one more node save later.

Can't see where to go, but I'll give the drupal_static_reset('token_menu_link_load'); a shot.

I'm on core 7.14 and pathauto-7.x-1.2

If you change the menu item's placement, that too won't reflect the updated path.

drupal_static_reset('token_menu_link_load_all_parents'), in addition to #9, should set you up.

Version:7.x-1.0» 7.x-1.2
Status:Postponed (maintainer needs more info)» Active

I think I've diagnosed this.

Do others have the Menu Browser (menuux) module installed?

I had:

system.name  system.weight
pathauto     1
menuux       10

so I set Pathauto's weight to 11 manually. That seems to have worked.

It's probably a problem best solved in Menu Browser - if others agree we can move to that issue queue.

Related issue (but not really a duplicate): #1131490: Pahtauto menu link patterns