diff --git a/includes/menu.inc b/includes/menu.inc index 5582c45..43b22ce 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -2689,11 +2689,16 @@ function _menu_link_build($item) { function _menu_navigation_links_rebuild($menu) { // Add normal and suggested items as links. $menu_links = array(); + $menu_drop = array(); foreach ($menu as $path => $item) { if ($item['_visible']) { $menu_links[$path] = $item; $sort[$path] = $item['_number_parts']; } + // Identify MENU_CALLBACK items; used to discard records in menu_links. + if ($item['type'] === MENU_CALLBACK) { + $menu_drop[$path] = $item; + } } if ($menu_links) { // Keep an array of processed menu links, to allow menu_link_save() to @@ -2767,10 +2772,12 @@ function _menu_navigation_links_rebuild($menu) { ->execute(); } } - // Find any item whose router path does not exist any more. + // Find any item whose router path does not exist any more OR which has + // become a MENU_CALLBACK and needs deletion from the menu_links table. + $paths_drop = array_keys($menu_drop); $result = db_select('menu_links') ->fields('menu_links') - ->condition('router_path', $paths, 'NOT IN') + ->condition(db_or()->condition('router_path', $paths, 'NOT IN')->condition('router_path',$paths_drop, 'IN')) ->condition('external', 0) ->condition('updated', 0) ->condition('customized', 0) diff --git a/modules/simpletest/tests/menu_alter_callback.info b/modules/simpletest/tests/menu_alter_callback.info new file mode 100644 index 0000000..bd5cd4d --- /dev/null +++ b/modules/simpletest/tests/menu_alter_callback.info @@ -0,0 +1,9 @@ +name = Menu Alter Callback +description = Alteration of Menu to CALLBACK to test removal from cache +package = menu_alter_callback +version = VERSION +core = 7.x + +hidden = TRUE +files[] = menu_alter_callback.module +files[] = menu_alter_callback.test diff --git a/modules/simpletest/tests/menu_alter_callback.module b/modules/simpletest/tests/menu_alter_callback.module new file mode 100644 index 0000000..cfe1b2b --- /dev/null +++ b/modules/simpletest/tests/menu_alter_callback.module @@ -0,0 +1,38 @@ + 'Menu_Alter_Callback Test', + 'page callback' => '_menu_alter_callback_content', + 'access callback' => TRUE, + 'type' => menu_alter_callback_change(), + ); + return $items; +} + +/** + * Dummy callback for hook_menu() to point to. + * + * @return + * A random string. + */ +function _menu_alter_callback_content() { + return 'This is _menu_alter_callback_content().'; +} + +/** + * Helper function for testMenuAlterCallback. + */ +function menu_alter_callback_change($new_type = '') { + static $type = MENU_NORMAL_ITEM; + if ($new_type == 'callback') { + $type = MENU_CALLBACK; + } + return $type; +} diff --git a/modules/simpletest/tests/menu_alter_callback.test b/modules/simpletest/tests/menu_alter_callback.test new file mode 100644 index 0000000..589c8da --- /dev/null +++ b/modules/simpletest/tests/menu_alter_callback.test @@ -0,0 +1,36 @@ + 'Menu alter callback', + 'description' => 'Tests that menu items altered from NORMAL to CALLBACK are removed from the registry on a rebuild.', + 'group' => 'Menu', + ); + } + + function setUp() { + parent::setUp('menu_alter_callback'); + } + + function testMenuAlterCallback() { + // Check that the test menu item exists. + $sql = "SELECT type FROM {menu_links}, {menu_router} WHERE {menu_links}.router_path = {menu_router}.path AND {menu_links}.router_path = 'menu_alter_callback'"; + $type = db_query($sql)->fetchField(); + $this->assertEqual($type, MENU_NORMAL_ITEM, t('Menu item exists and is type MENU_NORMAL_ITEM.')); + + // Change item type to MENU_CALLBACK and rebuild menu. + menu_alter_callback_change('callback'); + menu_rebuild(); + + $result = db_query($sql)->rowCount(); + $this->assertEqual($result, 0, t('Menu item no longer exists in menu_links table after menu_rebuild.')); + } +}