Have to publish twice to update URL alias (pathauto)

Created on 26 October 2023, about 1 year ago
Updated 26 July 2024, 4 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

RTBC

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States cxc891

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

Merge Requests

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.

  • πŸ‡ΊπŸ‡ΈUnited States ian.ssu

    I'm running out of time and want to share findings after spending much of today debugging problem I'm thinking is related to this issue. When adding adding a menu link to an existing Node the following error is throw

    Drupal\Core\Entity\EntityStorageException: Plugin ID 'menu_link_content:8a547baa-d9f5-458b-9cc7-939e642f78db' was not found. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    EntityFormDisplay->extractFormValues->getRenderer
    WorkflowButtonsWidget->extractFormValues($items, $form, $form_state) - $entity->isDefaultRevision() stays FALSE
    vs
    ModerationStateWidget->extractFormValues($items, $form, $form_state) - $entity->isDefaultRevision() changes TRUE

    In ModerationStateFieldItemList->updateModeratedEntity (line 167)
    $entity->isDefaultRevision($update_default_revision);

    From my testing it's this Node->isDefaultRevision() FALSE that is causing the issue with menu_link_content postSave

    Got to run but I believe there is something different between to WorkflowButtonsWidget and ModerationStateWidget at the heart of this issue.

  • Pipeline finished with Success
    4 months ago
    Total: 178s
    #226031
  • πŸ‡ΊπŸ‡ΈUnited States ian.ssu

    I think I found what is happening. The OptionsWidgetBase::validateElement method fails to correctly set the $form_state for moderation_state. This causes issues in ModerationStateFieldItemList->updateModeratedEntity, preventing the detection of moderation state changes. Consequently, this leads to downstream issues with pathauto. I've created MR 16 adding WorkflowButtonsWidget::validateElement.

  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Wow, awesome work!

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

    I can confirm that adding WorkflowButtonsWidget::validateElement fixes my issue. I tested it after setting the module weight back to default (0) and everything is working as expected.

  • Pipeline finished with Skipped
    4 months ago
    #235072
  • Status changed to RTBC 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA
Production build 0.71.5 2024