diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index e9dd15dbeea582e355c219a640269bd1584de6e1..f57404f5379edac344e1a274c94f19309cf508d1 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -91,7 +91,16 @@ public function form(array $form, FormStateInterface $form_state) { $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId(); $id = $this->entity->isNew() ? '' : $this->entity->getPluginId(); - $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $id); + if ($this->entity->isNew()) { + $menu_id = $this->entity->getMenuName(); + $menu = $this->entityTypeManager->getStorage('menu')->load($menu_id); + $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $id, [ + $menu_id => $menu->label(), + ]); + } + else { + $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $id); + } $form['menu_parent']['#weight'] = 10; $form['menu_parent']['#title'] = $this->t('Parent link'); $form['menu_parent']['#description'] = $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'); diff --git a/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php index e5d8070439e495695c078dba20f44ce6912cae56..fa4d8cc11a19c077716fb2b3e718e124000dab26 100644 --- a/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php +++ b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php @@ -72,6 +72,9 @@ public function testMenuLinkContentFormLinkToAnyPage() { $this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit'); $this->assertSession()->statusCodeEquals(200); + // Test that other menus are available when editing existing menu link. + $this->assertSession()->optionExists('edit-menu-parent', 'main:'); + $this->drupalLogin($this->basicUser); $this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit'); @@ -83,6 +86,8 @@ public function testMenuLinkContentFormLinkToAnyPage() { */ public function testMenuLinkContentForm() { $this->drupalGet('admin/structure/menu/manage/admin/add'); + // Test that other menus are not available when creating a new menu link. + $this->assertSession()->optionNotExists('edit-menu-parent', 'main:'); $option = $this->assertSession()->optionExists('edit-menu-parent', 'admin:'); $this->assertTrue($option->isSelected()); // Test that the field description is present. diff --git a/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php index 9cb7d40d03a7f17a2275fe53cba343ae5d8251ba..92e607bf14302b0e6c742d653ff1aef3292ce4d1 100644 --- a/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php @@ -806,7 +806,7 @@ public function checkInvalidParentMenuLinks() { 'expanded[value]' => FALSE, 'weight[0][value]' => '0', ]; - $this->drupalGet("admin/structure/menu/manage/{$this->menu->id()}/add"); + $this->drupalGet("admin/structure/menu/manage/tools/add"); $this->submitForm($edit, 'Save'); $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $title]); $last_link = reset($menu_links); @@ -814,7 +814,7 @@ public function checkInvalidParentMenuLinks() { } // The last link cannot be a parent in the new menu link form. - $this->drupalGet('admin/structure/menu/manage/admin/add'); + $this->drupalGet('admin/structure/menu/manage/tools/add'); $value = 'tools:' . $last_link->getPluginId(); $this->assertSession()->optionNotExists('edit-menu-parent', $value);