Verified Commit c90f093c authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3110371 by omkar.podey, idebr, gabesullice, joseph.olstad, fengtan,...

Issue #3110371 by omkar.podey, idebr, gabesullice, joseph.olstad, fengtan, el7cosmos, lauriii, Abhijith S, catch, smustgrave: When adding a new menu link, restrict the available parents to the current menu
parent 3165269b
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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();
    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.');
+5 −0
Original line number Diff line number Diff line
@@ -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.
+2 −2
Original line number Diff line number Diff line
@@ -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);