This question relates to How do I redirect a taxonomy menu item to another path?How do I redirect a taxonomy menu item to another path?
I followed the recommendations of Clive and wrote a hook_menu_alter to provide my callback.
function material_menu_taxonomy_page_callback($term) {
dsm('Entered material menu callback');
}
function material_menu_menu_alter () {
$items['taxonomy/term/%taxonomy_term']['page callback'] = 'material_menu_taxonomy_page_callback';
}
I placed a code line dsm("Altering");
in the callback to see where in the process the callback is being called, but it never shows up.
I am fairly certain that I have the code correct.
- The hook has the name of the custom module.
- The callback name is correct.
- the callback is in the same file as the hook
- I have turned the module off and then on so that I can be sure that Drupal knows about
mymodule_menu_alter
- And I have flushed the caches.
My assumption is that mymodule_menu_alter()' should change the callback in the menu item array and that the callback will be called each time the menu item is selected. That suggests that my
dsm()` message should display at the top of the page requested by the menu.
While Clive's test indicated in his answer worked, my revisions did not. Following Clive's answer recommendations I revised the code as follows.
material.info file contained in modules subdirectory = sites/all/modules/Custom/material
name = Materials
description = Redefine the path for materials menu
package = CR-Hub
core = 7.x
; Includes
files[] = material.module
material.module file in same subdirectory
function material_taxonomy_page_callback() {
drupal_goto('taxonomy/term/1');
// return 'Entered material menu callback';
}
function material_menu_alter(&$items) {
// return 'Entered Material Menu Alter';
$items['taxonomy/term/%taxonomy_term']['page callback'] = 'material_taxonomy_page_callback';
return $items;
}
When I select any menu item neither drupal_goto()
, or return 'any text'
lines redirect the selected path from the menu item.