Menu link exception on non-default revision

Created on 7 August 2025, 2 months ago

Problem/Motivation

When a node has a default revision and an associated menu link, creating a new revision without setting it as the default revision leaves the menu link unchanged, as expected.

However, when both the token and menu_ui modules are enabled, saving the draft triggers an update on the menu link. Since the node revision is not marked as default, this results in an inconsistency, and an exception is thrown during the menu link update process.

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 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Drupal\Core\Entity\EntityStorageBase->save() (Line: 804)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 370)
Drupal\Core\Entity\EntityBase->save() (Line: 726)
token_node_menu_link_submit()

Steps to reproduce

  1. Create a node, add a menu link to it, and publish it.
  2. Edit the content and create a new revision as draft.
  3. Save the draft.
  4. ๐Ÿ’ฅ

Tested on Drupal 11.2.2 with Token 1.15.0.

Proposed resolution

Mark the menu link entity for a new revision if the node's current revision is not the default one.

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

1.15

Component

Code

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance johnatas

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

Comments & Activities

  • Issue created by @johnatas
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance johnatas

    Attached patch fixes the issue on my end.
    So far, I haven't noticed any side effects, but I'll continue testing and report back if anything comes up.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States chinnu76

    I can reproduce the issue and confirm that the patch allows you to bypass the error

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States leraa

    I can confirm this patch worked on my 11.2.2 site where content moderation was blowing up on content types using menu link.

  • First commit to issue fork.
  • @jernejmramor opened merge request.
  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia jernejmramor

    Hello,

    I've tested this as well and I can confirm that this patch resolves the issue when you're using Drupal 11.2.x and Token 1.15.0.

    However out of curiosity I've tested the same issue with Drupal 11.1.8 and Token 1.15.0 and I couldn't reproduce this issue using the same steps.
    So I don't think this issue is happening due to something being wrong with this module, but rather a change made in Drupal core from 11.1.8 to ^11.2. I've investigated a bit what this change may be, but haven't been able to find it.

    I've opened a MR for this, by applying patch provided in #2 ๐Ÿ› Menu link exception on non-default revision Active for easier merging and test coverage. Tests are currently failing on dev branch so it might be worth fixing them first and then merging and reviewing this issue. Updating status to needs review.

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil charlliequadros

    Hi everyone,

    The change that is causing this error is already documented in this Drupal issue. https://www.drupal.org/project/drupal/issues/3499181#comment-16166844 ๐Ÿ› Disallow saving the current default revision as a non-default revision Active , there is a reference to a ticket ๐Ÿ“Œ Avoid incorrect and unecessary menu_link_content entity saving Active that provides the solution to the problem.

    I believe it would be better to close this ticket and keep the solution documented in the other one. I tested the PR from the other issue and it worked as expected.

    Iโ€™d like to hear your thoughts on this.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance johnatas

    Hello @charlliequadros,

    Thanks for the information. Iโ€™m not sure how I missed this during my research before creating my ticket.

    Youโ€™re absolutely right โ€” the root cause is the same, and the patch / MR from #3511768 ๐Ÿ“Œ Avoid incorrect and unecessary menu_link_content entity saving Active does fix the issue I reported.

    Iโ€™m closing this issue.

Production build 0.71.5 2024