Problem/Motivation

If a menu link has been added to a node, the associated layout builder form cannot save due to the menu settings form being absent.

Proposed resolution

Fix MenuSettingsConstraintValidator to be sensitive to contexts where the menu settings are not present because the form is not present.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Sam152 created an issue. See original summary.

sam152’s picture

Status: Active » Needs review
StatusFileSize
new998 bytes
new1.94 KB

The last submitted patch, 2: 3048698-2--TEST-ONLY.patch, failed testing. View results

fenstrat’s picture

Status: Needs review » Reviewed & tested by the community

This makes a lot of sense, good catch.

+++ b/core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php
@@ -76,6 +77,12 @@ public function testLayoutModeration() {
+    _menu_ui_node_save($node, [

Seems odd calling this "internal" function, but it's already called in LayoutBuilderModerationTest::testModerationWithNodeAndMenuSettings(), so fair enough.

sam152’s picture

Priority: Normal » Major

Bumping to major since authored content in the LB is essentially lost/unsavable when this is triggered.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php
--- a/core/modules/menu_ui/src/Plugin/Validation/Constraint/MenuSettingsConstraintValidator.php
+++ b/core/modules/menu_ui/src/Plugin/Validation/Constraint/MenuSettingsConstraintValidator.php

+++ b/core/modules/menu_ui/src/Plugin/Validation/Constraint/MenuSettingsConstraintValidator.php
@@ -16,8 +16,10 @@ class MenuSettingsConstraintValidator extends ConstraintValidator {
+      if (!$values = $entity->menu) {
+        return;
+      }

My original thought is that this fix looks good but I think we could do with a comment in the code about when this might happen.

However whilst asking myself the question - how does this happen I'm no longer sure. $entity->menu is added by menu_ui_node_builder() which is added by a form alter - menu_ui_form_node_form_alter(). But the constraint is added on menu_ui_entity_type_build() level - so it is always present. Which makes the menu_ui not the most API friendly module. Is there an existing issue which covers this problem?

The solution here might be the most pragmatic as a quick fix - but I think we at least need a comment that covers the why.

sam152’s picture

Essentially if the entity form is missing the menu UI form elements, the $entity->menu array never gets built and the validator does weird things. My assumption was, if no menu form elements were present on the form, the validator doesn't need to protect against changes to the associated menu link.

Can add a comment to that effect in the validator.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new936 bytes
new2.18 KB
tedbow’s picture

Status: Needs review » Reviewed & tested by the community

This seems like a good fix and comment.

Looked around for other issues. It seems weird to use Entity constraint for something that is only added via a form. I think if you were doing the same action say over JSON API you would make to POST/PATCH requests because this is actually 2 different content entities. In that case a entity level constraint makes no sense. So that would mean moving from using an entity constraint to I guess form validation function.

If others agree we could make a follow up I think this issue looks good.

alexpott’s picture

Issue tags: +Needs followup

Very happy to explore the correct fix in a follow-up. Let's create that first though.

tedbow’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed e07c22588a to 8.8.x and cef261ecea to 8.7.x. Thanks!

As a major bug fix backported to 8.7.x.

  • alexpott committed e07c225 on 8.8.x
    Issue #3048698 by Sam152, alexpott, tedbow, fenstrat: Content moderation...

  • alexpott committed cef261e on 8.7.x
    Issue #3048698 by Sam152, alexpott, tedbow, fenstrat: Content moderation...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.