Have to publish twice to update URL alias (pathauto)

Created on 26 October 2023, 8 months ago
Updated 15 December 2023, 7 months ago

Problem/Motivation

After switching from "moderation state" to "workflow buttons" widget, URL alias (pathauto) are not updated when moving a page within the menu.

Steps to reproduce

1. Set up pathauto pattern '/[node:menu-link:parents:join-path]/[node:menu-link]'
2. Create a "News" page and an "About" page
3. Create a "News 1" page and "About 1" page, and put them under each menu parent item
4. Now we have "/news/news1" and "/about/about1"
5. Set up content type to use workflow_buttons
6. Go to about1 page and put it under /news menu parent, publish
7. Expect to see URL as "/news/about1" but it's still "/about/about1"
8. Publish the page again and now URL is "/news/about1"
But...
9. The issue seems to be isolated to the [node:menu-link:parents:join-path] token, the other token [node:menu-link] gets instantly updated.

Proposed resolution

URL should get updated the first time a user clicks "Publish".

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States cxc891

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @cxc891
  • πŸ‡ΊπŸ‡ΈUnited States cxc891
  • πŸ‡ΊπŸ‡ΈUnited States cxc891

    Fixed it by lowering the module weight so it runs before the token module.

  • πŸ‡―πŸ‡΅Japan ultrabob Japan

    We could update the install hook and add an update hook to set the module weight to be lower than the token module's if it is installed, but it would be better to figure out the cause. I couldn't immediately identify what would be happening as a result of submitting via workflow buttons as opposed to selecting the target state and saving.
    I'm running out of time to look at this today, but it seems like the next step is identifying what is happening on a workflow_buttons submission that would undo the work that token does on save.

    That is just in case it gives somebody else a jumping-off point for trying to identify the culprit.

    @cxc891 did you identify something in particular that lead you to the module weight solution?

  • πŸ‡ΊπŸ‡ΈUnited States cxc891

    Thanks for looking into it @ultrabob

    I started to believe it might be the weight when I set a breakpoint inside the function "token_node_menu_link_submit" in token.module file. The $node object has something strange going on. $node['#values']['isDefaultRevision']=>["x-default"=>"1"]however, the "isDefaultRevision()" method returns false.

    Inside the same function, a MenuLinkContent entity is created using data from $node. And there is $entity->isDefaultRevision($node->isDefaultRevision()); before the entity is saved. This takes the "false" value from above and assigns it to the entity, which leads to the MenuLinkContent::postSave not updating the menu tree.

    The same issue was causing me a WSOD if I edit a node that's never in a menu and assign it a menu parent. I got something like a "menu plugin not found" error message. Makes sense given my investigation above.

    I checked the code from this module too but couldn't find anything that might be a culprit...

  • πŸ‡―πŸ‡΅Japan ultrabob Japan

    workflow_buttons_preprocess_node in workflow_buttons.module is where isDefaultRevision gets set. There is another issue for removing that preprocess πŸ› Remove unused preprocess Needs work . It would be interesting to know if removing that preprocess hook would fix this issue.

  • πŸ‡ΊπŸ‡ΈUnited States cxc891

    Hmm, I thought the preprocess was just to make extra variables avail to the templates. Anyway, the issue is not gone when the function is commented out.

    I'm now thinking if it's something inside the WorkflowButtonsWideget class. Either the formElement or the processActions function, whichever is responsible for loading and passing the entity to downstream modules.

  • πŸ‡ΊπŸ‡ΈUnited States cxc891

    I think we need to borrow a line from the content_moderation core module, inside the formElement function there is this line to load the most recent revision

    $original_entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadRevision($entity->getLoadedRevisionId());
    

    I will test and report.

  • πŸ‡―πŸ‡΅Japan ultrabob Japan

    @cxc891. Do you have anything to report back on this?

  • πŸ‡ΊπŸ‡ΈUnited States cxc891

    @ultrabob, yes. However, deleting the whole preprocess section does not change anything, nor does the code in #8.

Production build 0.69.0 2024