Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu link parent can be lost after saving a page as draft and then published #3241

Closed
bberndt-uaz opened this issue Mar 5, 2024 · 6 comments · Fixed by #3303
Closed

Menu link parent can be lost after saving a page as draft and then published #3241

bberndt-uaz opened this issue Mar 5, 2024 · 6 comments · Fixed by #3303
Assignees
Labels
bug Something isn't working editor experience Improvements to the editor experience for individuals editing Quickstart websites high priority Must get done for this milestone migration Related to the D7 to D9 migration no backport Features included with the next minor release only patch release Issues to be included in the next patch release

Comments

@bberndt-uaz
Copy link
Contributor

bberndt-uaz commented Mar 5, 2024

Problem/Motivation

An issue was introduced with Drupal 10.2 (Quickstart 2.9.0) which may result in the menu link for a page having its parent item removed, so that the menu item is moved to the top level of the menu. This appears to only occur when using a content moderation workflow.

Describe the bug

The issue may be related to the langcode field for menu links.

  1. Menu links that are susceptible to this problem have the langcode und (for "undetermined") in the database.
  2. Saving the associated page as a Draft updates the langcode field to en in the menu_link_content, menu_link_content_field_revision, and menu_link_content_revision tables.
  3. Finally, when the page is saved again as Published, the langcode field changes to en in menu_link_content_data. This is also when the parent value is set to NULL. (The expanded field is also changed from 0 to NULL.)
  4. However, if you set the parent menu link back to what it should be, repeating the previous steps will not cause it to change to NULL again, possibly because the langcode is already en.

I was able to reproduce this issue on a fresh Quickstart build with the demo content installed by manually changing the langcode field for a menu link from en to und in the menu_link_content tables in the database. After saving the page as Draft and then saving it as Published, the parent field for the menu link was set to NULL.

@trackleft noted that this issue may be related to the following Drupal change records and issues:

To Reproduce

Steps to reproduce the behavior:

  1. Edit a page in the menu with a parent menu item. In the database, the page's menu item must have a langcode that is different from the menu itself (such as und).
  2. Change the state to Draft and save the page.
  3. Edit the page again, change the state to Published, and save the page.
  4. The parent menu item for the page will change to Main Navigation, thus adding the page to the main nav. No errors are shown.

Proposed resolution

Still to be determined.

Expected behavior

Saving new revisions of a page, regardless of moderation state, should not change the parent menu item for the page.

Additional context

This has been confirmed to affect multiple Arizona Sites.

@bberndt-uaz bberndt-uaz added the bug Something isn't working label Mar 5, 2024
@bberndt-uaz bberndt-uaz changed the title Menu link parent can be lost after saving a page as draft and then published [Placeholder] Menu link parent can be lost after saving a page as draft and then published Mar 6, 2024
@bberndt-uaz bberndt-uaz added needs discussion Further discussion required to determine requirements high priority Must get done for this milestone and removed needs discussion Further discussion required to determine requirements labels Mar 6, 2024
@bberndt-uaz
Copy link
Contributor Author

Next steps:

  • Determine which Quickstart versions this problem affects
  • Determine possible solutions

@bberndt-uaz
Copy link
Contributor Author

bberndt-uaz commented Mar 6, 2024

  • I tested a Pantheon multidev on Quickstart 2.7.5 (Drupal 10.0) and could not reproduce the issue. Saving a page as draft and then as published resulted in no change to the associated menu link: the langcode remained as und.
  • I also tested a multidev that @trackleft set up on Quickstart 2.8.9 (Drupal 10.1) and could not reproduce the issue. Saving a page as draft and then as published resulted in no change to the associated menu link: the langcode remained as und.
  • Finally, I tested a multidev that @trackleft set up on Quickstart 2.9.0 (Drupal 10.2.2) and did reproduce the issue. Saving a page as draft and then as published resulted in a change to the associated menu link: the langcode changed from und to en.

@joeparsons
Copy link
Member

joeparsons commented Mar 7, 2024

@joeparsons
Copy link
Member

joeparsons commented Mar 12, 2024

I think I found the actual 10.2.x change that is causing this problem:
https://git.drupalcode.org/project/drupal/-/commit/91acedade93894c41d3aef75a6c7511a9db6be29

Basically code was added to the core menu_ui module that ensures the langcode of menu links matches the associated node's langcode when nodes are saved.

Drupal.org issue associated with the change:
https://www.drupal.org/project/drupal/issues/2904899

@joeparsons
Copy link
Member

My working theory after looking through a bunch of issues and code history on Drupal.org is:

  • This is likely only affecting sites with menu links that were migrated using our Quickstart migration(s)
  • The change that was included in 10.2 that updates the menu_link_content langcode value if it doesn't match the associated node's langcode value makes discrepancies between between langcode values for parent/child menu links much more likely
  • When those discrepancies exist, the content moderation issue that resets the parent value of the menu link seems to occur when publishing a draft revision of the associated node

I verified that:

  • The schema for menu_links in D7 did not include a language/langcode value by default (see system.install#L1272-1456)
  • The langcode value for menu_links migrated with az_migration's az_menu_linksmigration is set to und by default (see az_menu_links.yml#L23-L26)
  • New menu links and content nodes created on Quickstart 2 sites have a langcode value of en by default (unless the site has configured a different default language configured in system.site default_langcode?)
  • Creating a draft revision on a newly created page + menu link and then resaving to publish the revision does not seem cause the content_revision issue to occur that resets the menu link parent value

@joeparsons joeparsons moved this from Todo to In Progress in 2.9.x Issues Mar 12, 2024
@joeparsons joeparsons added the migration Related to the D7 to D9 migration label Mar 15, 2024
@bberndt-uaz
Copy link
Contributor Author

Next steps: Create a PR that adds a database update to change menu links with the und langcode to have the site's default langcode instead. The PR can also update the az_menu_links migration. We will need to test the database update on a site with multiple languages. For the migration, we should consider that the source site and destination site may not have the same languages.

@joeparsons joeparsons added the editor experience Improvements to the editor experience for individuals editing Quickstart websites label Mar 15, 2024
joeparsons added a commit that referenced this issue Mar 28, 2024
@joeparsons joeparsons moved this from In Progress to Ready to merge in 2.9.x Issues Apr 2, 2024
@joeparsons joeparsons added patch release Issues to be included in the next patch release no backport Features included with the next minor release only and removed 2.9.x only labels Apr 2, 2024
trackleft pushed a commit that referenced this issue Apr 3, 2024
@github-project-automation github-project-automation bot moved this from Ready to merge to Done in 2.9.x Issues Apr 3, 2024
@trackleft trackleft removed this from 2.9.x Issues Apr 3, 2024
@trackleft trackleft moved this to Done in 2.9.6 Patch Release Apr 3, 2024
@trackleft trackleft moved this from Todo to Done in 2.9.x Issues Apr 3, 2024
trackleft pushed a commit that referenced this issue Apr 4, 2024
@joeparsons joeparsons removed this from 2.9.x Issues Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working editor experience Improvements to the editor experience for individuals editing Quickstart websites high priority Must get done for this milestone migration Related to the D7 to D9 migration no backport Features included with the next minor release only patch release Issues to be included in the next patch release
Projects
No open projects
2 participants