Пример #1
0
 /**
  * Create a simple hierarchy of links.
  */
 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', 'bundle' => 'menu_link_content');
     $parent = $base_options + array('route_name' => 'menu_test.hierarchy_parent');
     $link = entity_create('menu_link_content', $parent);
     $link->save();
     $links['parent'] = $link->getPluginId();
     $child_1 = $base_options + array('route_name' => '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('route_name' => 'menu_test.hierarchy_parent_child2', '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('route_name' => 'menu_test.hierarchy_parent_child2', '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('route_name' => '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;
 }
Пример #2
0
 /**
  * Create a simple hierarchy of links.
  */
 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 = MenuLinkContent::create($parent);
     $link->save();
     $links['parent'] = $link->getPluginId();
     $child_1 = $base_options + array('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 + array('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 + array('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 + array('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;
 }
 /**
  * Tests deleting all the links in a menu.
  */
 public function testDeleteLinksInMenu()
 {
     \Drupal::entityManager()->getStorage('menu')->create(array('id' => 'menu1'))->save();
     \Drupal::entityManager()->getStorage('menu')->create(array('id' => 'menu2'))->save();
     \Drupal::entityManager()->getStorage('menu_link_content')->create(array('route_name' => 'menu_test.menu_name_test', 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'))->save();
     \Drupal::entityManager()->getStorage('menu_link_content')->create(array('route_name' => 'menu_test.menu_name_test', 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'))->save();
     \Drupal::entityManager()->getStorage('menu_link_content')->create(array('route_name' => 'menu_test.menu_name_test', 'menu_name' => 'menu2', 'bundle' => 'menu_link_content'))->save();
     $output = $this->linkTree->load('menu1', new MenuTreeParameters());
     $this->assertEqual(count($output), 2);
     $output = $this->linkTree->load('menu2', new MenuTreeParameters());
     $this->assertEqual(count($output), 1);
     $this->menuLinkManager->deleteLinksInMenu('menu1');
     $output = $this->linkTree->load('menu1', new MenuTreeParameters());
     $this->assertEqual(count($output), 0);
     $output = $this->linkTree->load('menu2', new MenuTreeParameters());
     $this->assertEqual(count($output), 1);
 }