diff -u menu_block.admin.inc menu_block.admin.inc --- menu_block.admin.inc 2010-08-31 03:58:19.000000000 +0000 +++ menu_block.admin.inc 2010-09-10 04:58:06.000000000 +0000 @@ -41,6 +41,7 @@ } drupal_set_message(t('The block has been created.')); + menu_block_get_delta(0,TRUE); cache_clear_all(); $form_state['redirect'] = 'admin/build/block'; @@ -90,6 +91,7 @@ db_query("DELETE FROM {blocks} WHERE module = 'menu_block' AND delta = %d", $delta); db_query("DELETE FROM {blocks_roles} WHERE module = 'menu_block' AND delta = %d", $delta); drupal_set_message(t('The "%name" block has been removed.', array('%name' => $form_state['values']['block_title']))); + menu_block_get_delta(0,TRUE); cache_clear_all(); $form_state['redirect'] = 'admin/build/block'; return; diff -u menu_block.module menu_block.module --- menu_block.module 2010-08-31 16:12:51.000000000 +0000 +++ menu_block.module 2010-09-10 05:22:12.000000000 +0000 @@ -218,34 +218,44 @@ } /** + * Return block delta given global block ID. + * + * @param $bid + * integer Global block ID from core Block module. + * @param $reset + * Boolean Clear function's static cache and return empty result. + * + * @return + * integer Block delta relative to menu_block. + */ +function menu_block_get_delta($bid,$reset=FALSE) { + static $blocks = array(); + if ($reset) { + $blocks = array(); + return $blocks; + } + if (!array_key_exists($bid,$blocks)) { + $block = db_fetch_array(db_query("SELECT module, delta FROM {blocks} WHERE bid = %d", $bid)); + $blocks[$bid] = $block; + } + $delta = 0; + $block = $blocks[$bid]; + if ($block && ($block['module'] == "menu_block")) { + $delta = $block['delta']; + } + return $delta; +} + +/** * Build a menu tree based on the provided configuration. * * @param $config - * array An array of configuration options that specifies how to build the - * menu tree and its title. - * - delta: (string) The menu_block's block delta. - * - menu_name: (string) The machine name of the requested menu. Can also be - * set to MENU_TREE__CURRENT_PAGE_MENU to use the menu selected by the page. - * - parent_mlid: (int) The mlid of the item that should root the tree. Use 0 - * to use the menu's root. - * - title_link: (boolean) Specifies if the title should be rendered as a link - * or a simple string. - * - admin_title: (string) An optional title to uniquely identify the block on - * the administer blocks page. - * - class_name: (string) An optional additional class name for the menu - * - level: (int) The starting level of the tree. - * - follow: (string) Specifies if the starting level should follow the - * active menu item. Should be set to 0, 'active' or 'child'. - * - depth: (int) The maximum depth the tree should contain, relative to the - * starting level. - * - expanded: (boolean) Specifies if the entire tree be expanded or not. - * - sort: (boolean) Specifies if the tree should be sorted with the active - * trail at the top of the tree. + * Block configuration. See menu_tree_build() for details. + * * @return - * array An array containing the rendered tree in the 'content' key and the - * rendered title in the 'subject' key. + * See menu_tree_page_data() for a description of the data structure. */ -function menu_tree_build($config) { +function menu_block_tree_build($config) { // Retrieve the active menu item from the database. if ($config['menu_name'] == MENU_TREE__CURRENT_PAGE_MENU) { // Retrieve the list of available menus. @@ -327,6 +337,42 @@ menu_tree_sort_active_path($tree); } + return $tree; +} + +/** + * Build and render a menu tree based on the provided configuration. + * + * @param $config + * array An array of configuration options that specifies how to build the + * menu tree and its title. + * - delta: (string) The menu_block's block delta. + * - menu_name: (string) The machine name of the requested menu. Can also be + * set to MENU_TREE__CURRENT_PAGE_MENU to use the menu selected by the page. + * - parent_mlid: (int) The mlid of the item that should root the tree. Use 0 + * to use the menu's root. + * - title_link: (boolean) Specifies if the title should be rendered as a link + * or a simple string. + * - admin_title: (string) An optional title to uniquely identify the block on + * the administer blocks page. + * - class_name: (string) An optional additional class name for the menu + * - level: (int) The starting level of the tree. + * - follow: (string) Specifies if the starting level should follow the + * active menu item. Should be set to 0, 'active' or 'child'. + * - depth: (int) The maximum depth the tree should contain, relative to the + * starting level. + * - expanded: (boolean) Specifies if the entire tree be expanded or not. + * - sort: (boolean) Specifies if the tree should be sorted with the active + * trail at the top of the tree. + * @return + * array An array containing the rendered tree in the 'content' key and the + * rendered title in the 'subject' key. + */ +function menu_tree_build($config) { + + // Build the tree + $tree = menu_block_tree_build($config); + // Render the tree. $data = array(); $data['subject'] = menu_block_get_title($config['title_link'], $config);