コード例 #1
0
ファイル: LinksTest.php プロジェクト: alnutile/drunatra
 /**
  * Create a simple hierarchy of links.
  */
 function createLinkHierarchy($module = 'menu_test')
 {
     // First remove all the menu links.
     $menu_links = menu_link_load_multiple();
     menu_link_delete_multiple(array_keys($menu_links), TRUE, TRUE);
     // Then create a simple link hierarchy:
     // - $parent
     //   - $child-1
     //      - $child-1-1
     //      - $child-1-2
     //   - $child-2
     $base_options = array('link_title' => 'Menu link test', 'module' => $module, 'menu_name' => 'menu_test');
     $links['parent'] = $base_options + array('link_path' => 'menu-test/parent');
     $links['parent'] = entity_create('menu_link', $links['parent']);
     $links['parent']->save();
     $links['child-1'] = $base_options + array('link_path' => 'menu-test/parent/child-1', 'plid' => $links['parent']['mlid']);
     $links['child-1'] = entity_create('menu_link', $links['child-1']);
     $links['child-1']->save();
     $links['child-1-1'] = $base_options + array('link_path' => 'menu-test/parent/child-1/child-1-1', 'plid' => $links['child-1']['mlid']);
     $links['child-1-1'] = entity_create('menu_link', $links['child-1-1']);
     $links['child-1-1']->save();
     $links['child-1-2'] = $base_options + array('link_path' => 'menu-test/parent/child-1/child-1-2', 'plid' => $links['child-1']['mlid']);
     $links['child-1-2'] = entity_create('menu_link', $links['child-1-2']);
     $links['child-1-2']->save();
     $links['child-2'] = $base_options + array('link_path' => 'menu-test/parent/child-2', 'plid' => $links['parent']['mlid']);
     $links['child-2'] = entity_create('menu_link', $links['child-2']);
     $links['child-2']->save();
     return $links;
 }
コード例 #2
0
 /**
  * Tests toolbar_menu_link_update() hook implementation.
  */
 function testMenuLinkUpdateSubtreesHashCacheClear()
 {
     // Get subtree items for the admin menu.
     $query = \Drupal::entityQuery('menu_link');
     for ($i = 1; $i <= 3; $i++) {
         $query->sort('p' . $i, 'ASC');
     }
     $query->condition('menu_name', 'admin');
     $query->condition('depth', '2', '>=');
     // Build an ordered array of links using the query result object.
     $links = array();
     if ($result = $query->execute()) {
         $links = menu_link_load_multiple($result);
     }
     // Get the first link in the set.
     $links = array_values($links);
     $link = array_shift($links);
     // Disable the link.
     $edit = array();
     $edit['enabled'] = FALSE;
     $this->drupalPostForm("admin/structure/menu/item/" . $link['mlid'] . "/edit", $edit, t('Save'));
     $this->assertResponse(200);
     $this->assertText('The menu link has been saved.');
     // Assert that the subtrees hash has been altered because the subtrees
     // structure changed.
     $this->assertDifferentHash();
 }