--- nodehierarchy.module 2009-10-31 15:35:01.000000000 -0400 +++ nodehierarchyNew.module 2009-11-09 18:25:30.000000000 -0500 @@ -593,6 +593,18 @@ function nodehierarchy_delete_node($node function nodehierarchy_node_delete_submit($form, $form_state) { $form_values = $form_state['values']; if ($form_values['confirm'] && $form_values['nodehierarchy_delete_children']) { + nodehierarchy_delete_children($form_values['nid']); + } +} + +/** + * Delete the nodehierarchy information when a node is deleted. + */ +function nodehierarchy_delete_children($nid) { + if ($nid) { + foreach (_nodehierarchy_get_descendant_list($nid) as $child) { + node_delete($child['nid']); + } } } @@ -821,6 +833,20 @@ function _nodehierarchy_get_children_men } /** + * Get the descendant tree for the given node. + */ +function _nodehierarchy_get_descendant_list($parent) { + $out = array(); + $children = _nodehierarchy_get_children_menu_links($parent); + $out = $children; + + foreach ($children as $child) { + $out = array_merge($out, _nodehierarchy_get_descendant_list($child['nid'])); + } + return $out; +} + +/** * Count the children of the given node. */ function _nodehierarchy_get_children_count($parent) {