Pathauto token for node menu hierarchy not working after updating parent node

Created on 28 November 2018, about 6 years ago
Updated 17 June 2024, 7 months ago

This is a cross-post of https://www.drupal.org/node/2691929 β†’ since the issue lies in Pathauto rather than Token.

As described on that issue, re: using a Pathauto pattern with ':menu-link:parent' token/s, when updating the alias for an entity that has a menu link that is a parent, the aliases for the child menu links are not updated.

The attached patch adds a call at the end of PathautoGenerator::createEntityAlias() for insert or update operations (if alias changed) to update the aliases for any child menu link/s (if any) of the entity's menu link/s (if any). It only runs this update if any saved pathauto pattern contains ':menu-link:parent/s' tokens. Perhaps an admin setting for this might be preferred?

NB this only operates on entity insert/update, not on menu link hierarchy restructuring.

NB tested successfully with pattern '[node:menu-link:parent:url:relative]/[node:title]'. The pattern '[node:menu-link:parents:join-path]/[node:title]' seemed to replace with stale aliases, not sure of the issue.

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada bgilhome Victoria

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States Brandon Mok

    In the patch from #16, I noticed the check that determines if a child needs to be updated was always evaluating to TRUE for this particular condition $child_entity->id() !== $entity->id. The accessing of the entity's id through $entity->id was observed to return a NULL value every time despite there being a parent entity; thereby, resulting in a truthy check.

    Based on the #16 patch, the included patch and interdiff updates the condition so that the accessing of the entity's id is through the id() method of the EntityInterface: $entity->id().

Production build 0.71.5 2024