--- nodehierarchy.module.org 2009-01-09 15:43:51.000000000 +0100 +++ nodehierarchy.module 2009-01-09 15:09:44.000000000 +0100 @@ -215,12 +215,24 @@ function nodehierarchy_form_alter(&$form function nodehierarchy_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'fields': - return; + return; case 'insert': + nodehierarchy_invoke_api("update_parent", $node); + break; case 'update': nodehierarchy_invoke_api("update_parent", $node); break; case 'load': + + // Start hack + // Set nodehierarchy.order_by equal to menu_link.weight only on page load + // and not on AJAX updates + if (strpos($_GET['q'], 'ajax') === FALSE) + { + nodehierarchy_set_order_by_to_weight($node); + } + // End hack + return nodehierarchy_load_node($node); break; case 'delete': @@ -882,7 +894,11 @@ function _nodehierarchy_create_menu(&$no $item['link_title'] = trim($node->title); $item['link_path'] = "node/$node->nid"; - $item['weight'] = $node->order_by - 11; // Editable menu weight range used to start at -10. + + // Hack start + // $item['weight'] = $node->order_by - 11; // Editable menu weight range used to start at -10. + // Hack end + if (!menu_link_save($item)) { drupal_set_message(t('There was an error saving the menu link.'), 'error'); } @@ -906,9 +922,21 @@ function _nodehierarchy_set_menu_order($ // This is not possible for top level items, so we rearrange them anyway, since // this is usually the desired behaviour. if ($parent_menu = _nodehierarchy_get_parent_menu($parent, $nid)) { - if ($child_menu = _nodehierarchy_get_child_menu($nid, $parent_menu['mlid'])) { + + // Hack start + if ($child_menu = _nodehierarchy_get_child_menu($nid, $parent_menu['plid'])) { + //if ($child_menu = _nodehierarchy_get_child_menu($nid, $parent_menu['mlid'])) { + // Hack end + $link = menu_link_load($child_menu['mlid']); - $link['weight'] = ($order_by-11); + + // Hack start + $node->nid = $nid; + $node_additions = nodehierarchy_load_node($node); + $link['weight'] = $node_additions['order_by']; + //$link['weight'] = ($order_by-11); + // Hack end + menu_link_save($link); return TRUE; } @@ -920,7 +948,11 @@ function _nodehierarchy_set_menu_order($ * Find the menu ID for the given node. */ function _nodehierarchy_get_menu($nid) { - return db_fetch_array(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", "node/$nid", 0, 1)); + + // Hack start + return db_fetch_array(db_query_range("SELECT mlid, plid FROM {menu_links} WHERE link_path = '%s'", "node/$nid", 0, 1)); + //return db_fetch_array(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", "node/$nid", 0, 1)); + // Hack end } /** @@ -944,6 +976,16 @@ function _nodehierarchy_get_child_menu($ return db_fetch_array(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = '%s' AND plid = '%d'", "node/$nid", $plid, 0, 1)); } + +/** + * Set nodehierarchy.order_by equal to menu_link.weight + */ +function nodehierarchy_set_order_by_to_weight($node) { + db_query("UPDATE {nodehierarchy}, {menu_links} SET {nodehierarchy}.order_by = {menu_links}.weight + WHERE {menu_links}.link_path = '%s' + AND {nodehierarchy}.nid = %d", "node/" . $node->nid, $node->nid); +} + /** * Get the parent selector pulldown. */