addMenuLink example

$this->drupalLogin($this->drupalCreateUser([
      'administer menu',
      'access contextual links',
      'administer blocks',
    ]));
    $menu = $this->addCustomMenu();

    $block = $this->drupalPlaceBlock('system_menu_block:' . $menu->id()[
      'label' => 'Custom menu',
      'provider' => 'system',
    ]);
    $this->addMenuLink('', '/', $menu->id());

    $this->drupalGet('test-page');

    // Click on 'Configure block' contextual link.     $this->clickContextualLink("#block-{$block->id()}", 'Configure block');
    // Check that we're on block configuration form.     $this->assertNotEmpty($this->getSession()->getPage()->findLink('Remove block'));

    $this->drupalGet('test-page');

    // Click on 'Edit menu' contextual link.

    ]);

    // Verify add link button.     $this->drupalGet('admin/structure/menu');
    $this->assertSession()->linkByHrefExists('admin/structure/menu/manage/' . $menu_name . '/add', 0, "The add menu link button URL is correct");

    // Verify form defaults.     $this->doMenuLinkFormDefaultsTest();

    // Add menu links.     $item1 = $this->addMenuLink('', '/node/' . $node1->id()$menu_name, TRUE);
    $item2 = $this->addMenuLink($item1->getPluginId(), '/node/' . $node2->id()$menu_name, FALSE);
    $item3 = $this->addMenuLink($item2->getPluginId(), '/node/' . $node3->id()$menu_name);

    // Hierarchy     // <$menu_name>     // - item1     // -- item2     // --- item3
    $this->assertMenuLink([
      'children' => [$item2->getPluginId()$item3->getPluginId()],
      


  /** * Tests with a simple linear hierarchy. */
  public function testSimpleHierarchy() {
    // Add some links with parent on the previous one and test some values.     // <tools>     // - test1     // -- test2     // --- test3     $this->addMenuLink('test1', '');
    $this->assertMenuLink('test1', ['has_children' => 0, 'depth' => 1]);

    $this->addMenuLink('test2', 'test1');
    $this->assertMenuLink('test1', ['has_children' => 1, 'depth' => 1][]['test2']);
    $this->assertMenuLink('test2', ['has_children' => 0, 'depth' => 2]['test1']);

    $this->addMenuLink('test3', 'test2');
    $this->assertMenuLink('test1', ['has_children' => 1, 'depth' => 1][]['test2', 'test3']);
    $this->assertMenuLink('test2', ['has_children' => 1, 'depth' => 2]['test1']['test3']);
    $this->assertMenuLink('test3', ['has_children' => 0, 'depth' => 3]['test2', 'test1']);
  }

  
Home | Imprint | This part of the site doesn't use cookies.