Since pathauto simply calls node_load_multiple() and then processes the nodes in the order in which they were created, the token [node:menu-link:parent:url:path] might fail since menu children may get processed before their parent.

Reordering the nodes themselves according to their menu links might be out of the scope of pathauto. I'd therefore suggest to at least add an alter hook to pathauto_node_update_alias_multiple() that allows other modules to reorder the nodes before each node gets processed by pathauto_node_update_alias(). If not, then the proper way to do this would be via hook_query_pathauto_bulk_update_alter(), since every bulk update query gets tagged with "pathauto_bulk_update".

CommentFileSizeAuthor
#1 pathauto-bulk-items-alter-2464291-1.patch1.89 KBciss
PASSED: [[SimpleTest]]: [MySQL] 337 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

ciss’s picture

Status: Active » Needs review
FileSize
1.89 KB
PASSED: [[SimpleTest]]: [MySQL] 337 pass(es). View

Attached patch provides a new hook hook_pathauto_update_alias_multiple_alter(array &$entities, $entity_type). For the sake of consistency I've added the hook to pathauto_node_update_alias_multiple(), pathauto_taxonomy_term_update_alias_multiple() and pathauto_user_update_alias_multiple().

ciss’s picture

Issue summary: View changes
Status: Needs review » Active

Disregard. I just realized two things:

  1. The hook is called way too late to have the intended effect.
  2. The proper way to handle this is to implement hook_query_pathauto_bulk_update_alter().
ciss’s picture

Solving this turns out to be more complicated than I anticipated. It's not enough to just implement hook_query_pathauto_bulk_update_alter() because pathauto uses the (incrementing) node id to segment the batches. Seems that hook_batch_alter() is also needed to override the batch process callback.
The orderBy should happen via (menu_link.depth, nid). This needs to reflect in $sandbox['current'].

thelmer’s picture