public function MenuLinksOriginTest::createLinkHierarchy in Menu Item Extras 8.2
Create a simple hierarchy of links.
1 call to MenuLinksOriginTest::createLinkHierarchy()
- MenuLinksOriginTest::testMenuLinkReparenting in tests/
src/ Kernel/ MenuLinksOriginTest.php - Test automatic reparenting of menu links.
File
- tests/
src/ Kernel/ MenuLinksOriginTest.php, line 73
Class
- MenuLinksOriginTest
- Tests handling of menu links hierarchies.
Namespace
Drupal\Tests\menu_item_extras\KernelCode
public 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 = [
'title' => 'Menu link test',
'provider' => $module,
'menu_name' => 'menu_test',
];
$parent = $base_options + [
'link' => [
'uri' => 'internal:/menu-test/hierarchy/parent',
],
];
$link = MenuLinkContent::create($parent);
$link
->save();
$links['parent'] = $link
->getPluginId();
$child_1 = $base_options + [
'link' => [
'uri' => 'internal:/menu-test/hierarchy/parent/child',
],
'parent' => $links['parent'],
];
$link = MenuLinkContent::create($child_1);
$link
->save();
$links['child-1'] = $link
->getPluginId();
$child_1_1 = $base_options + [
'link' => [
'uri' => 'internal:/menu-test/hierarchy/parent/child2/child',
],
'parent' => $links['child-1'],
];
$link = MenuLinkContent::create($child_1_1);
$link
->save();
$links['child-1-1'] = $link
->getPluginId();
$child_1_2 = $base_options + [
'link' => [
'uri' => 'internal:/menu-test/hierarchy/parent/child2/child',
],
'parent' => $links['child-1'],
];
$link = MenuLinkContent::create($child_1_2);
$link
->save();
$links['child-1-2'] = $link
->getPluginId();
$child_2 = $base_options + [
'link' => [
'uri' => 'internal:/menu-test/hierarchy/parent/child',
],
'parent' => $links['parent'],
];
$link = MenuLinkContent::create($child_2);
$link
->save();
$links['child-2'] = $link
->getPluginId();
return $links;
}