Avoid incorrect and unecessary menu_link_content entity saving

Created on 8 March 2025, 4 months ago

Problem/Motivation

See πŸ“Œ MenuTreeStorage shouldn't invalidate cache tags if the menu didn't change Active and πŸ› Disallow saving the current default revision as a non-default revision Active There is code copied from menu_ui and also additional extra savings that will break those performance optimizations and for the second issue, likely result in fatal errors.

Should extend \Drupal\Tests\menu_ui\Functional\MenuUiNodeTest and \Drupal\Tests\menu_ui\Functional\MenuUiContentModerationTest and run them with token.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

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

Merge Requests

Comments & Activities

  • Issue created by @berdir
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Neat, we already have the subclass for content_moderation and that fails on 11.x with an exception, as expected. Added the other one too and refactored the code to be similar to core.

    Really wish all of this wouldn't be necessary. At least it should only save it once now and we have extensive test coverage.

  • πŸ‡¬πŸ‡§United Kingdom andy_w

    I think I came to a very similar conclusion ( https://www.drupal.org/project/drupal/issues/3486604 πŸ› Node edit form re-saves menu items even if no change has occurred Active ), but then got side-tracked by the rabbit hole of the menu name return issue, I like the self-contained nature of this patch, looks good, I'll try and find the time to give it a test later today on some of our sites.

  • Status changed to Needs review 11 days ago
  • πŸ‡ΊπŸ‡ΈUnited States slbrassard

    The patch works for me on a Drupal 11.2 site.

  • Works for me as well in 11.2. Thanks a lot!

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    For context, the blocker here is getting tests and logic to work on both old and new core versions. If it's just tests then I'm OK with skipping them on older versions, but it still needs to somewhat work on older versions.

  • πŸ‡¦πŸ‡ΊAustralia timfletcher

    I've tested MR !90 on Core 11.2.2 and it works nicely.

    I was originally getting this error:

    Drupal\Core\Entity\EntityStorageException: An existing default revision of the 'menu_link_content' entity type can not be changed to a non-default revision. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of /var/www/html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    This was blocking saving draft revisions of published content with a menu position assigned. My URLs use Token to generate the path based on parent menu item URLs.

    There are some side effects though - when explicitly updating the Menu item content in an unpublished revision of a live node, it breaks the menu interface. I'm including it here for posterity:

    This warning appears (hard to read, at least in the Gin theme):

    <Menu name> contains 1 menu link with pending revisions. Manipulation of a menu tree having links with pending revisions is not supported, but you can re-enable manipulation by getting each menu link to a published state.

    Here's an example menu after publishing a node:

    I then published another Page, but then changed the menu item title manually and saved the node as a Draft revision:

    The same menu then shows a broken structure:

  • πŸ‡¦πŸ‡ΊAustralia timfletcher

    There seems to be another issue arising here; if the menu item title saved in the draft revision doesn't match the node title in the published revision, the menu nav stays broken when the node is published:

    I changed the title of the menu item via the Menu Item UI, and it saved fine:

    I then edited the Page node and the updated menu link title appeared correctly. I changed the menu item title and saved the Page as a Published revision:

    This should have resolved the moderation state of the menu item and allowed the Menu UI to work again but it stayed broken until I explicitly unchecked 'Provide a menu link' and re-checked it, which resets the menu item title text to match the node's title.

Production build 0.71.5 2024