nid] = $book_node; } foreach($nodes as $node) { $nodes[$node->nid]->book_id = _book_get_top_level($node, $nodes); $node->depth = 1; } // Make sure that parent nodes get links before their children _book_reorder_by_depth($nodes); foreach($nodes as $node) { if($node->depth == 1) { $plid = 0; } menu_link_save(array('link_title' => $node->title, 'link_path' => 'node/'. $node->nid, 'router_path' => 'node/%', Array ( [link_title] => zxcv [link_path] => node/2 [router_path] => node/% [menu_name] => book-toc-1 [module] => book [plid] => 97 ) } } else { // no exising nodes in the hierarchy $ret = db_update_sql("DROP TABLE {book}"); drupal_install_schema('book'); } return $ret; } function _book_get_top_level($node, $nodes) { if($node->parent == 0) { return $node->nid; } else { $node->depth++; return _book_get_top_level($nodes[$node->parent], $nodes); } } function _book_reorder_by_depth(&$nodes) { $nodes_new = array(); foreach($nodes as $node) { $nodes_new[$node->depth] = $node; } ksort($nodes_new); $nodes = $nodes_new; }