Commit 249e5252 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2858434 by amateescu, timmillwood, plach: (Followup to) menu changes...

Issue #2858434 by amateescu, timmillwood, plach: (Followup to) menu changes from node form leak into live site when creating draft revision
parent 930a35b9
......@@ -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) {
......
......@@ -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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment