diff --git a/core/modules/menu_ui/src/Plugin/Validation/Constraint/MenuSettingsConstraintValidator.php b/core/modules/menu_ui/src/Plugin/Validation/Constraint/MenuSettingsConstraintValidator.php index a27cbe9..b43b565 100644 --- a/core/modules/menu_ui/src/Plugin/Validation/Constraint/MenuSettingsConstraintValidator.php +++ b/core/modules/menu_ui/src/Plugin/Validation/Constraint/MenuSettingsConstraintValidator.php @@ -26,28 +26,30 @@ public function validate($entity, Constraint $constraint) { } // Handle the case when a menu link is added to a forward revision. - if ($defaults['entity_id'] != $values['entity_id']) { + if (!$defaults['entity_id'] && $values['enabled']) { $violation_path = 'menu'; } // Handle the case when the menu link is deleted in a forward revision. - elseif (empty($values['enabled'] && $values['entity_id'])) { + elseif (empty($values['enabled']) && $defaults['entity_id']) { $violation_path = 'menu'; } // Handle all the other menu link changes in a forward revision. - elseif (($values['title'] != $defaults['title'])) { - $violation_path = 'menu.title'; - } - elseif (($values['description'] != $defaults['description'])) { - $violation_path = 'menu.description'; - } - elseif (($values['menu_name'] != $defaults['menu_name'])) { - $violation_path = 'menu.menu_parent'; - } - elseif (($values['parent'] != $defaults['parent'])) { - $violation_path = 'menu.menu_parent'; - } - elseif (($values['weight'] != $defaults['weight'])) { - $violation_path = 'menu.weight'; + elseif ($defaults['entity_id']) { + if (($values['title'] != $defaults['title'])) { + $violation_path = 'menu.title'; + } + elseif (($values['description'] != $defaults['description'])) { + $violation_path = 'menu.description'; + } + elseif ($defaults['entity_id'] && ($values['menu_name'] != $defaults['menu_name'])) { + $violation_path = 'menu.menu_parent'; + } + elseif (isset($values['parent']) && ($values['parent'] != $defaults['parent'])) { + $violation_path = 'menu.menu_parent'; + } + elseif (($values['weight'] != $defaults['weight'])) { + $violation_path = 'menu.weight'; + } } if ($violation_path) { diff --git a/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php index 85eb6ad..a593b36 100644 --- a/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php @@ -58,6 +58,14 @@ public function testMenuUiWithForwardRevisions() { // Create a node. $node = $this->drupalCreateNode(); + // Publish the node with no changes. + $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and Publish')); + $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()])); + + // Create a forward revision with no changes. + $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and Create New Draft')); + $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()])); + // Add a menu link and save a new default (published) revision. $edit = [ 'menu[enabled]' => 1, @@ -126,6 +134,21 @@ public function testMenuUiWithForwardRevisions() { // Check that the menu settings were not applied. $this->assertSession()->pageTextNotContains('You can only change the menu settings for the published version of this content.'); $this->assertSession()->linkExists('Test menu link'); + + // Create a node. + $node = $this->drupalCreateNode(); + + // Publish the node with no changes. + $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and Publish')); + $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()])); + + // Add a menu link and save and create a new non-default (draft) revision. + $edit = [ + 'menu[enabled]' => 1, + 'menu[title]' => 'Test menu link', + ]; + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and Create New Draft')); + $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.'); } }