You are here

function LinksTest::createLinkHierarchy in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/menu_link_content/src/Tests/LinksTest.php \Drupal\menu_link_content\Tests\LinksTest::createLinkHierarchy()

Create a simple hierarchy of links.

1 call to LinksTest::createLinkHierarchy()
LinksTest::testMenuLinkReparenting in core/modules/menu_link_content/src/Tests/LinksTest.php
Test automatic reparenting of menu links.

File

core/modules/menu_link_content/src/Tests/LinksTest.php, line 52
Contains \Drupal\menu_link_content\Tests\LinksTest.

Class

LinksTest
Tests handling of menu links hierarchies.

Namespace

Drupal\menu_link_content\Tests

Code

function createLinkHierarchy($module = 'menu_test') {

  // First remove all the menu links in the menu.
  $this->menuLinkManager
    ->deleteLinksInMenu('menu_test');

  // Then create a simple link hierarchy:
  // - parent
  //   - child-1
  //      - child-1-1
  //      - child-1-2
  //   - child-2
  $base_options = array(
    'title' => 'Menu link test',
    'provider' => $module,
    'menu_name' => 'menu_test',
  );
  $parent = $base_options + array(
    'link' => [
      'uri' => 'internal:/menu-test/hierarchy/parent',
    ],
  );
  $link = entity_create('menu_link_content', $parent);
  $link
    ->save();
  $links['parent'] = $link
    ->getPluginId();
  $child_1 = $base_options + array(
    'link' => [
      'uri' => 'internal:/menu-test/hierarchy/parent/child',
    ],
    'parent' => $links['parent'],
  );
  $link = entity_create('menu_link_content', $child_1);
  $link
    ->save();
  $links['child-1'] = $link
    ->getPluginId();
  $child_1_1 = $base_options + array(
    'link' => [
      'uri' => 'internal:/menu-test/hierarchy/parent/child2/child',
    ],
    'parent' => $links['child-1'],
  );
  $link = entity_create('menu_link_content', $child_1_1);
  $link
    ->save();
  $links['child-1-1'] = $link
    ->getPluginId();
  $child_1_2 = $base_options + array(
    'link' => [
      'uri' => 'internal:/menu-test/hierarchy/parent/child2/child',
    ],
    'parent' => $links['child-1'],
  );
  $link = entity_create('menu_link_content', $child_1_2);
  $link
    ->save();
  $links['child-1-2'] = $link
    ->getPluginId();
  $child_2 = $base_options + array(
    'link' => [
      'uri' => 'internal:/menu-test/hierarchy/parent/child',
    ],
    'parent' => $links['parent'],
  );
  $link = entity_create('menu_link_content', $child_2);
  $link
    ->save();
  $links['child-2'] = $link
    ->getPluginId();
  return $links;
}