diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 04222d25bea3..95c9e3e81f0b 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -332,7 +332,12 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) { '#default_value' => $defaults['weight'], '#description' => t('Menu links with lower weights are displayed before links with higher weights.'), ); - $form['actions']['submit']['#submit'][] = 'menu_ui_form_node_form_submit'; + + foreach (array_keys($form['actions']) as $action) { + if (isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') { + $form['actions'][$action]['#submit'][] = 'menu_ui_form_node_form_submit'; + } + } } /** diff --git a/core/modules/menu_ui/src/Tests/MenuNodeTest.php b/core/modules/menu_ui/src/Tests/MenuNodeTest.php index ce234fcabffb..8e14d412ac25 100644 --- a/core/modules/menu_ui/src/Tests/MenuNodeTest.php +++ b/core/modules/menu_ui/src/Tests/MenuNodeTest.php @@ -17,6 +17,13 @@ use Drupal\menu_link_content\Entity\MenuLinkContent; */ class MenuNodeTest extends WebTestBase { + /** + * An editor user. + * + * @var \Drupal\user\UserInterface + */ + protected $editor; + /** * Modules to enable. * @@ -31,14 +38,15 @@ class MenuNodeTest extends WebTestBase { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); - $this->drupalLogin($this->drupalCreateUser(array( + $this->editor = $this->drupalCreateUser(array( 'access administration pages', 'administer content types', 'administer menu', 'create page content', 'edit any page content', 'delete any page content', - ))); + )); + $this->drupalLogin($this->editor); } /** @@ -104,6 +112,36 @@ class MenuNodeTest extends WebTestBase { $this->drupalGet('test-page'); $this->assertNoLink($node_title); + // Use not only the save button, but also the two special buttons: + // 'Save and publish' as well as 'Save and keep published'. + // These buttons just appear for 'administer nodes' users. + $admin_user = $this->drupalCreateUser([ + 'access administration pages', + 'administer content types', + 'administer nodes', + 'administer menu', + 'create page content', + 'edit any page content', + ]); + $this->drupalLogin($admin_user); + foreach ([t('Save and unpublish') => FALSE, t('Save and keep unpublished') => FALSE, t('Save and publish') => TRUE, t('Save and keep published') => TRUE] as $submit => $visible) { + $edit = [ + 'menu[enabled]' => 1, + 'menu[title]' => $node_title, + ]; + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, $submit); + // Assert that the link exists. + $this->drupalGet('test-page'); + if ($visible) { + $this->assertLink($node_title, 0, 'Found a menu link after submitted with ' . $submit); + } + else { + $this->assertNoLink($node_title, 'Found no menu link after submitted with ' . $submit); + } + } + + // Log back in as normal user. + $this->drupalLogin($this->editor); // Edit the node and create a menu link. $edit = array( 'menu[enabled]' => 1,