diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index eb1de17..53bd456 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -366,16 +366,28 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) { */ function menu_ui_form_node_form_submit($form, FormStateInterface $form_state) { $node = $form_state->getFormObject()->getEntity(); - - // Prevent changes to the menu settings if the node being saved is not the - // default revision. - if (!$node->isDefaultRevision()) { - drupal_set_message(t('This is not the default revision. You can only change the menu settings for the published version of this content.'), 'error'); - return; - } - if (!$form_state->isValueEmpty('menu')) { $values = $form_state->getValue('menu'); + + // Prevent changes to the menu settings if the node being saved is not the + // default revision. + $defaults = menu_ui_get_menu_link_defaults($node); + if (trim($values['title']) && !empty($values['menu_parent'])) { + list($menu_name, $parent) = explode(':', $values['menu_parent'], 2); + $values['menu_name'] = $menu_name; + $values['parent'] = $parent; + } + $updated = (empty($values['enabled'] && $values['entity_id'])) + || ($values['title'] != $defaults['title']) + || ($values['description'] != $defaults['description']) + || ($values['menu_name'] != $defaults['menu_name']) + || ($values['parent'] != $defaults['parent']) + || ($values['weight'] != $defaults['weight']); + if ($updated && !$node->isDefaultRevision()) { + drupal_set_message(t('This is not the default revision. You can only change the menu settings for the published version of this content.'), 'error'); + return; + } + if (empty($values['enabled'])) { if ($values['entity_id']) { $entity = MenuLinkContent::load($values['entity_id']); diff --git a/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php index 5cfb5a1..3d6fa56 100644 --- a/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php @@ -89,6 +89,14 @@ public function testMenuUiWithForwardRevisions() { // Check that the menu settings were not applied. $this->assertSession()->pageTextContains('This is not the default revision. You can only change the menu settings for the published version of this content.'); $this->assertSession()->linkExists('Test menu link'); + + // Try to save a new non-default (draft) revision without any changes and + // check that the error message is not shown. + $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and Create New Draft')); + + // Check that the menu settings were not applied. + $this->assertSession()->pageTextNotContains('This is not the default revision. You can only change the menu settings for the published version of this content.'); + $this->assertSession()->linkExists('Test menu link'); } }